Module-findGeogCoord.nb

Written by Vince Cronin

Begun February 24, 2021;  revised February 28, 2021

Introduction

The purpose of this notebook is to test the module findGeogCoord[] , which is designed to convert a unit location vector, expressed in a Cartesian geographic coordinate system, into the latitude and longitude in the geographic coordinate system.

Specify 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 lat, long, a, b, and θ 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 θ is the angle between vector {vect[[1]], vect[[2]], 0} and vector {1, 0, 0} expressed in radian measure.

Variable b is the same as angle θ (if the second element – the Y component – of the input vector is zero or a positive value) or its inverse, -θ, (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,θ},a=ArcSin[vect[[3]]];θ=If[((Abs[vect[[1]]]<(1×(10^(-14))))&&(Abs[vect[[2]]]<(1×(10^(-14))))),0,ArcCos[vect[[1]]/(Sqrt[(((vect[[1]])^2)+((vect[[2]])^2))])]];
b=If[(vect[[2]]<0),(-θ),(θ)];lat=a(180/π);long=If[((Abs[vect[[1]]]<(1×(10^(-14))))&&(Abs[vect[[2]]]<(1×(10^(-14))))),0,(b(180/π))];{lat,long}];

Test the user - defined functions

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

inputCoords={{0,0},{0,45},{0,90},{0,135},{0,180},{0,-45},{0,-90},{0,-135},{0,-180},{45,0},{45,45},{45,90},{45,135},{45,180},{45,-45},{45,-90},{45,-135},{45,-180},{-45,0},{-45,45},{-45,90},{-45,135},{-45,180},{-45,-45},{-45,-90},{-45,-135},{-45,-180},{90,0},{-90,0}};

a=Dimensions[inputCoords];

length=a[[1]]

inLat=35;

inLong=125;

convert2cart[inLat,inLong];

N[%]

trial=Table[testUserDefinedFunctions[inputCoords[[i,1]],inputCoords[[i,2]]],{i,1,length}];

Table[{trial[[i,1]],trial[[i,2]],inputCoords[[i,1]],inputCoords[[i,2]]},{i,1,length}];

MatrixForm[%]