Code: Select all
EarthRadius.d = 6378.1370; 6372.795477598;6,378.1370
Structure point3d
x.d
y.d
z.d
EndStructure
Structure point2d
x.d
y.d
EndStructure
ProcedureDLL DEG_TO_RAD()
ProcedureReturn 1/0.0174532925199432958
EndProcedure
ProcedureDLL RAD_TO_DEG()
ProcedureReturn 1/57.29577951308232
EndProcedure
; /**
; * Convert [lat,lon] polar coordinates To [x,y,z] cartesian coordinates
; * @param {Number} lon
; * @param {Number} lat
; * @param {Number} radius
; * @return {Vector3}
; */
; Latitude is the Y axis, longitude is the X axis.
; function polarToCartesian( lon, lat, radius ) {
;
; var phi = ( 90 - lat ) * DEG2RAD
; var theta = ( lon + 180 ) * DEG2RAD
;
; Return {
; x: -(radius * Math.sin(phi) * Math.sin(theta)),
; y: radius * Math.cos(phi),
; z: radius * Math.sin(phi) * Math.cos(theta),
; }
;
; }
ProcedureDLL PolarToCartesian(x.d,y.d,r.d,*return.point3d)
phi.d = (90 - y) * DEG_TO_RAD()
theta.d =(x + 180) * DEG_TO_RAD()
*return\x = (r * Sin(phi) * Sin(theta))
*return\y = r * Cos(Phi)
*return\z = r * Sin(phi) * Cos(theta)
ProcedureReturn *return
EndProcedure
; /**
; * Convert [x,y,z] cartesian coordinates To polar [lat,lon]
; * @param {Vector3} coord
; * @return {Array<Number>}
; */
; function cartesianToPolar( coord, radius ) {
;
; var lon = Math.atan2( coord.x, -coord.z ) * RAD2DEG
; var length = Math.sqrt( coord.x * coord.x + coord.z * coord.z )
; var lat = Math.atan2( coord.y, length ) * RAD2DEG
;
; Return [ lon, lat ]
;
; }
ProcedureDLL CartesianToPolar(coord.point3d,radius,*return.point2d)
lon.d = ATan2(coord\x, coord\z) * RAD_TO_DEG
length.d Sqr(coord\x, coord\x + coord\z * coord\z)
lat.d = ATan2(coord\y,length) * RAD_TO_DEG
*return\x = lon
*return\y = lat
ProcedureReturn *return
EndProcedure