-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXYZ to lat long.cpp
73 lines (69 loc) · 1.38 KB
/
XYZ to lat long.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <bits/stdc++.h>
using namespace std;
double toRad(double x)
{
return x/57.29577;
}
double toDeg(double x)
{
return x*57.29577;
}
void printDMS(double f)
{
int x=(floor(f));
int y=(floor((f-x)*60));
double z=(((f-x)*60)-y)*60;
int u=roundf(z);
cout<< x<<"°"<<y<<"'"<<u <<"\""<<endl;;
}
double sqr(double x)
{
return x*x;
}
int main()
{
double a,f,x,y,z =0.0;
double lat,lon =0.0;
cout<<"Enter the following values:"<<endl;
cout<<"a:";
cin>>a;
cout<<"\n1/f:";
cin>>f;
cout<<"\nX:";
cin>>x;
cout<<"\nY:";
cin>>y;
cout<<"\nZ:";
cin>>z;
cout<<endl;
lon= atan(y/x);
////end of longitude
double latNew = asin(z/a);
// cout<<latNew<<endl;
double b=((f*a)-a)/f;
// cout<<b<<endl;
long double e =((a*a)-(b*b))/(b*b);
// cout<<setprecision(8)<<e<<endl;
int count=1;
do
{
lat= latNew;
double sinLat =sin(latNew);
double v= a/sqrt((1-(e*sqr(sinLat))));
latNew = atan((z+(v*e*sinLat))/sqrt(sqr(x)+sqr(y)));
cout<<"Iteration "<<count<<endl;
cout<<" V:"<<v<<endl;
cout<<" Lat:"<<latNew<<endl;
// cout<<"\n"<<lat<<endl;
// cout<<latNew<<endl;
count++;
}while(lat!=latNew || count ==11);
cout<<"\nFinal Results."<<endl;
//print Latitude
cout<<"\nLatitude: "<<toDeg(lat)<<endl;
printDMS(toDeg(lat));
//print Longitude
cout<<"\nLongitude: "<<toDeg(lon)<<endl;
printDMS(toDeg(lon));
return 0;
}