33import org .osm2world .core .map_data .creation .LatLon ;
44
55public class WGS84Util {
6+
7+ private static final double WGS84_A = 6378137.0 ;
8+ private static final double WGS84_B = 6356752.3142451793 ;
9+
610 private static final VectorXYZ oneOverRadiiSquared = new VectorXYZ (
7- 2.458172257647332e-14 , 2.458172257647332e-14 , 2.4747391015697002e-14 );
11+ 1.0 / (WGS84_A * WGS84_A ),
12+ 1.0 / (WGS84_A * WGS84_A ),
13+ 1.0 / (WGS84_B * WGS84_B ));
814
915 private static final VectorXYZ wgs84RadiiSquared =
10- new VectorXYZ (6378137.0 * 6378137.0 , 6378137.0 * 6378137.0 , 6356752.3142451793 * 6356752.3142451793 );
16+ new VectorXYZ (WGS84_A * WGS84_A , WGS84_A * WGS84_A , WGS84_B * WGS84_B );
1117
1218 public static VectorXYZ cartesianFromLatLon (LatLon origin , double height ) {
1319 double latitude = Math .toRadians (origin .lat );
@@ -20,21 +26,21 @@ public static VectorXYZ cartesianFromLatLon(LatLon origin, double height) {
2026 cosLatitude * Math .sin (longitude ),
2127 Math .sin (latitude ));
2228
23- scratchN = normalize (scratchN );
29+ scratchN = scratchN . normalize ();
2430
2531 VectorXYZ scratchK = mulByComponents (radiiSquared , scratchN );
26- double gamma = Math .sqrt (dot (scratchN , scratchK ));
27- scratchK = divideByScalar ( scratchK , gamma );
28- scratchN = multiplyByScalar ( scratchN , height );
32+ double gamma = Math .sqrt (scratchN . dot (scratchK ));
33+ scratchK = scratchK . mult ( 1.0 / gamma );
34+ scratchN = scratchN . mult ( height );
2935
30- return add (scratchK , scratchN );
36+ return scratchK . add (scratchN );
3137 }
3238
3339 public static double [] eastNorthUpToFixedFrame (VectorXYZ cartesian ) {
3440
3541 VectorXYZ normal = geodeticSurfaceNormal (cartesian );
36- VectorXYZ tangent = normalize ( new VectorXYZ (-cartesian .y , cartesian .x , 0.0 ));
37- VectorXYZ bitangent = cross (normal , tangent );
42+ VectorXYZ tangent = new VectorXYZ (-cartesian .y , cartesian .x , 0.0 ). normalize ( );
43+ VectorXYZ bitangent = normal . cross (tangent );
3844
3945 // Matrix 4x4 by columns
4046 return new double [] {
@@ -57,45 +63,13 @@ public static double[] eastNorthUpToFixedFrame(VectorXYZ cartesian) {
5763 };
5864 }
5965
60- public static VectorXYZ add (VectorXYZ left , VectorXYZ right ) {
61- return new VectorXYZ (left .x + right .x , left .y + right .y , left .z + right .z );
62- }
63-
64- public static VectorXYZ divideByScalar (VectorXYZ vector , double scalar ) {
65- return new VectorXYZ (vector .x / scalar , vector .y / scalar , vector .z / scalar );
66- }
67-
68- public static VectorXYZ multiplyByScalar (VectorXYZ vector , double scalar ) {
69- return new VectorXYZ (vector .x * scalar , vector .y * scalar , vector .z * scalar );
70- }
71-
72- public static double dot (VectorXYZ left , VectorXYZ right ) {
73- return left .x * right .x + left .y * right .y + left .z * right .z ;
74- }
75-
7666 public static VectorXYZ geodeticSurfaceNormal (VectorXYZ cartesian ) {
7767 VectorXYZ mulByComponents = mulByComponents (cartesian , oneOverRadiiSquared );
78- return normalize (mulByComponents );
79- }
80-
81- public static VectorXYZ cross (VectorXYZ left , VectorXYZ right ) {
82- double x = left .y * right .z - left .z * right .y ;
83- double y = left .z * right .x - left .x * right .z ;
84- double z = left .x * right .y - left .y * right .x ;
85-
86- return new VectorXYZ (x , y , z );
68+ return mulByComponents .normalize ();
8769 }
8870
8971 public static VectorXYZ mulByComponents (VectorXYZ a , VectorXYZ b ) {
9072 return new VectorXYZ (a .x * b .x , a .y * b .y , a .z * b .z );
9173 }
9274
93- public static VectorXYZ normalize (VectorXYZ a ) {
94- double m = magnitude (a );
95- return new VectorXYZ (a .x / m , a .y / m , a .z / m );
96- }
97-
98- public static double magnitude (VectorXYZ a ) {
99- return Math .sqrt (a .x * a .x + a .y * a .y + a .z * a .z );
100- }
10175}
0 commit comments