5 float distance(
double lat1,
double lon1,
double lat2,
double lon2){
6 if (lat1 == lat2 && lon1 == lon2)
return 0;
8 double aacos = cos(lat2/180*M_PI)*cos(lat1/180*M_PI)*
9 (cos((lon2-lon1)/180*M_PI))+sin(lat2/180*M_PI)
12 return (
float) acos(aacos)*6371;
17 double** SymMatrixtoTriang(
double** m,
int dim,
short returnlower){
19 double** tl = CreateMatrix(dim,dim);
23 for(j = 0; j < dim; j++)
24 for(i = 0; i <=j; i++){
26 for(k = 0;k < i; k++) sum = sum +
float(tl[k][j]*tl[k][i]);
29 tl[i][j] = sqrt(m[i][j]-sum);
38 tl[i][j] = (m[i][j]-sum)/tl[i][i];
43 TranspondMatrix(tl,dim);
47 double** CreateMatrix(
int dimx,
int dimy){
50 double** t =
new double*[dimx];
51 for(i = 0; i < dimx; i++)
52 t[i] =
new double[dimy];
55 for(i = 0; i < dimx; i++)
56 for(j = 0; j < dimy; j++)
61 double** CopyMatrix(
double** m,
int dimx,
int dimy){
62 double** t = CreateMatrix(dimx,dimy);
63 for(
int i = 0; i < dimx; i++)
64 for(
int j = 0; j < dimy; j++)
68 void DeleteMatrix(
double** m,
int dimx){
69 for(
int i= 0; i < dimx; i++)
73 void TranspondMatrix(
double** m,
int dim){
76 for(i = 0; i < dim; i++)
77 for(j = i+1; j < dim; j++){
83 double** MatrixMatrix(
double** m1,
int dim1x,
int dim1y,
84 double** m2,
int dim2x,
int dim2y){
86 double** r = CreateMatrix(dim2x,dim1y);
88 for(
int i = 0; i < dim2x; i++)
89 for(
int j = 0; j < dim1y; i++)
92 for(i = 0; i < dim2x; i++)
93 for(j = 0; j < dim1y; i++)
94 for(k = 0; k < dim1x; k++)
95 r[i][j] = r[i][j] + m1[k][j]*m2[i][k];
99 double* SymLGS(
double** A,
double* y,
int dim){
108 double* b =
new double[dim];
109 double* x =
new double[dim];
112 double** tl = SymMatrixtoTriang(A,dim,1);
113 if(tl == NULL) error++;
117 for(
int j = 0; j < dim; j++)
118 if(tl[j][j] == 0) error++;
122 for(
int j = 0; j < dim; j++){
124 for(i = j-1; i >= 0; i--) sum = sum + b[i]*tl[i][j];
125 b[j] = (y[j]-sum)/tl[j][j];
129 TranspondMatrix(tl,dim);
131 for(
int j = dim-1; j >= 0; j--){
133 for(i = j+1; i < dim; i++) sum = sum + x[i]*tl[i][j];
134 x[j] = (b[j]-sum)/tl[j][j];
141 DeleteMatrix(tl,dim);
152 double* FitPolynom(QPointF* p,
int pointcount,
int grad){
154 double* y =
new double[grad+1];
155 for(i = 0; i <= grad; i++) y[i] = 0;
156 double** A = CreateMatrix(grad+1,grad+1);
159 for(i = 0; i < pointcount; i++){
162 for(j = 0; j <= grad*2; j++){
165 while(xi <= grad && yi >= 0){
166 A[xi][yi] = A[xi][yi] + xn;
171 if(j <= grad) y[grad-j] = y[grad-j] + xn * p[i].y();
177 double* x = SymLGS(A,y,grad+1);
178 DeleteMatrix(A,grad+1);
182 double fpln(
double x,
double* p,
int grad){
184 for(
int k = 0; k <= grad; k++)
185 result = result + p[k]*pow(x,grad-k);
190 double upperscale(
float f){
194 while(pow(
double(10), i1) > f) i1--;
197 while(pow(
double(10), i1) < f) i1++;
200 double v = f/pow(
double(10), i1);
201 if(v < 2)
return pow(
double(10), i1)*2;
202 if(v < 2.5)
return pow(
double(10), i1)*2.5;
203 if(v < 5)
return pow(
double(10), i1)*5;
204 else return pow(
double(10), i1+1);
206 double fermi(
double x,
double max,
double T,
double x0){
209 return max/(1+exp((x-x0)/T));
211 double lattomercator(
double lat){
212 double sinlat = sin(lat/180.*M_PI);
214 return 1./2.*log((1+sinlat)/(1-sinlat))*180./M_PI;
216 return 1./2.*log((1-sinlat)/(1+sinlat))*180./M_PI;
218 double mercatortolat(
double mlat){
219 double explat = exp(2*mlat/180.*M_PI);
220 return asin((explat-1)/(explat+1))*180./M_PI;