-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCartPoint.cpp
70 lines (53 loc) · 1.1 KB
/
CartPoint.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
/*
* CartPoint.cpp
*
* Created on: Dec 24, 2016
* Author: froike
*/
#include "CartPoint.h"
#include <cmath>
#include <stdio.h>
/*
* Contractor
*/
CartPoint::CartPoint(){
_z=0; _y = 0; _x = 0;
}
CartPoint::CartPoint(double x, double y, double z){
_x = x;
_y = y;
_z = z;
}
double CartPoint::get_lat(){
return toDegrees(asin(_z / EARTH_RADIUS));
}
double CartPoint::get_lon(){
return toDegrees(atan2(_y,_x));
}
double CartPoint::get_alt(){
return sqrt(pow(_x,2) + pow(_y,2) + pow(_z,2)) - EARTH_RADIUS;
}
double CartPoint::get_x(){
return _x;
}
double CartPoint::get_y(){
return _y;
}
double CartPoint::get_z(){
return _z;
}
void CartPoint::printCart(){
printf("(CartPoint: x:%f y:%f z:%f)\n",_x, _y, _z);
}
void CartPoint::printGeo(){
printf("(CartPoint: lat:%f lon:%f alt:%f)\n",get_lat(), get_lon(), get_alt());
}
double CartPoint::distance(CartPoint other){
return sqrt(pow(_x - other._x, 2) + pow(_y - other._y, 2) +pow(_z - other._z, 2));
}
double toDegrees(double radians){
return (radians * 180) / M_PI;
}
double toRadians(double degrees){
return (M_PI * degrees) / 180;
}