hi everybody, i try to do a code to calculate with lattitude, longitude and time from a GPS the magnetic declination.
I found some java code on the internet and in convert it to arduino, but i am blocked with the multiple array can anybody help me ? (this is just the code for magnetic declination not the gps parser).magDec2010 and 2020 are in array tab of 72 columns and 35 rows ...
you can find it here : http://www.satellite-calculations.com/Satellite/scripts/magneticdeclination.online.sat.calc :
int interval = 5;
int timeA,timeB, timeNow;
double interpolate(double x1, double x2, double y1, double y2,double xn) {
double m,b;
double q = x2-x1;
if(q != 0.0) {
m = (y2-y1)/q;
} else {
m = 1e99;
}
b = y1-(x1*m);
return (m*xn)+b;
}
double getArrayVal(double array[35][72],int y,int x) {
double v = array[(y % 170)/interval][(x % 360)/interval];
return v;
}
double getLatVal(double array[35][72],int la1,int la2,int ln,double dla) {
double y1 = getArrayVal(array,la1,ln);
double y2 = getArrayVal(array,la2,ln);
return interpolate(la1,la2,y1,y2,dla);
}
double get2dVal(double array[35][72],int la1, int la2,int ln1,int ln2,double dla, double dln) {
double y1,y2;
y1 = getLatVal(array,la1,la2,ln1,dla);
y2 = getLatVal(array,la1,la2,ln2,dla);
return interpolate(ln1,ln2,y1,y2,dln); // interpolate in 2D
}
double getDeclination(double la, double ln) {
la += 85;
ln += 180;
double resA,resB;
int la1 = (int) la;
la1 = (la1/interval) * interval;
int la2 = la1+interval;
if(la2 >= 170) {
la1 -= interval;
la2 -= interval;
}
int ln1 = (int) ln;
ln1 = (ln1/interval) * interval;
int ln2 = ln1 + interval
if(ln2 >= 360) {
ln2 -= interval;
ln1 -= interval;
}
resA = get2dVal(magDec2010,la1,la2,ln1,ln2,la,ln);
resB = get2dVal(magDec2020,la1,la2,ln1,ln2,la,ln);
return interpolate(timeA,timeB,resA,resB,timeNow);
}
}*/
void setup()
{}
void loop()
{}