GeogCartGeog . nb

Written by Vince Cronin

Begun February 24, 2021

Create the user - defined functions

The module convert2cart is designed to convert a latitude and longitude in the geographic coordinate system into the corresponding unit location vector, expressed in a cartesian geographic coordinate system.

convert2cart[lat_, long_] := {Cos[lat Degree] Cos[long Degree], Cos[lat Degree] Sin[long Degree], Sin[lat Degree]};

The module findGeogCoord is designed to convert a unit location vector (expressed in a cartesian geographic coordinate system) into the equivalent latitude and longitude in the geographic coordinate system.

A global variable is passed to the module through the local variable vect_.  The input variable is a unit location vector.

Variables a, b, c, d, e, f, lat, and long are local variables defined within the module.

Variable a is the arcsine of the third element (i.e., the Z component) of the input unit location vector vect.

Variable b is a vector that is the projection of the input unit location vector onto the X-Y plane.

Variable c is the unit vector of variable b unless the input unit location vector is coincident with North or South Poles.  In other words, c = Normalize[b].

Variable d is the unit vector that coincides with the positive X axis (1 axis), which is the intersection of the Equator and the Prime Meridian.

Variable e is the angle between vector c and vector d expressed in radian measure.

Variable f is the same as angle e (if the second element – the Y component – of the input vector is zero or a positive value) or its inverse, -e, (if the Y component of the input vector is a negative value).

Variable lat is the decimal latitude of the input unit location vector.

Variable long is the decimal longitude of the input unit location vector.

findGeogCoord[vect_]:=Module[{lat,long,a,b,c,d,e,f},a=ArcSin[vect[[3]]];b={vect[[1]],vect[[2]],0};c=If[((Abs[vect[[1]]]<(1×(10^(-14))))&&(Abs[vect[[2]]]<(1×(10^(-14))))),If[(vect[[3]]<0),{0,0,-1},{0,0,1}],Normalize[b]];d={1,0,0};e=VectorAngle[c,d];f=If[(vect[[2]]<0),(-e),(e)];lat=a(180/π);long=If[((Abs[vect[[1]]]<(1×(10^(-14))))&&(Abs[vect[[2]]]<(1×(10^(-14))))),0,(f(180/π))];{lat,long}];

Test the user - defined functions

testUserDefinedFunctions[inLat_,inLong_]:=Module[{cartCoord,outLat,outLong,answer},cartCoord=convert2cart[inLat,inLong];answer=findGeogCoord[cartCoord];answer];

inLat=35;

inLong=125;

testUserDefinedFunctions[inLat,inLong];

N[%]