Created
December 5, 2019 02:16
-
-
Save cosinekitty/6524e37d56f6575564e24bdca8ad1b32 to your computer and use it in GitHub Desktop.
Rotate coordinate systems to facilitate calculating azimuth and altitude angles.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function RotateGlobe(b, a, bradius, aradius) | |
{ | |
// Get modified coordinates of 'b' by rotating the globe so that 'a' is at lat=0, lon=0. | |
var br = {lat:b.lat, lon:(b.lon - a.lon), elv:b.elv}; | |
var brp = LocationToPoint(br); | |
// Rotate brp cartesian coordinates around the z-axis by a.lon degrees, | |
// then around the y-axis by a.lat degrees. | |
// Though we are decreasing by a.lat degrees, as seen above the y-axis, | |
// this is a positive (counterclockwise) rotation (if B's longitude is east of A's). | |
// However, from this point of view the x-axis is pointing left. | |
// So we will look the other way making the x-axis pointing right, the z-axis | |
// pointing up, and the rotation treated as negative. | |
var alat = GeocentricLatitude(-a.lat * Math.PI / 180.0); | |
var acos = Math.cos(alat); | |
var asin = Math.sin(alat); | |
var bx = (brp.x * acos) - (brp.z * asin); | |
var by = brp.y; | |
var bz = (brp.x * asin) + (brp.z * acos); | |
return {x:bx, y:by, z:bz, radius:bradius}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment