Last active
November 21, 2019 04:57
-
-
Save davidcalhoun/d3416a79c2b8a342e63b9a0b47371300 to your computer and use it in GitHub Desktop.
satellite azim,elev to cartesian coords
This file contains hidden or 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
const elevToHypLength = (elev, canvasSize) => { | |
return canvasSize - (canvasSize * elev) / 89.99999999; | |
} | |
const deg2rad = deg => (Math.PI * 2 * deg) / 360; | |
const toFixedFloat = (num = 0, digitsAfterDecimal = 0) => parseFloat(num.toFixed(digitsAfterDecimal)) | |
const getXY = (azim, elev, canvasSize) => { | |
const hyp = elevToHypLength(elev, canvasSize / 2); | |
const angle = deg2rad(azim % 90); | |
const opp = toFixedFloat(Math.sin(angle) * hyp, 2); | |
const adj = toFixedFloat(Math.cos(angle) * hyp, 2); | |
// return x, y coords in the orientation of compass directions. | |
// 0 = N, 90 = E, 180 = S, 270 = W | |
// need to do some basic coord transforms because the triangle math won't work without 90 deg | |
// triangles (degress 0-90 only), also to account for compass directions, which are rotated and | |
// flipped, as opposed to standard math orientation | |
if (azim >= 0 && azim < 90) { | |
return [opp, adj]; | |
} | |
if (azim >= 90 && azim < 180) { | |
return [adj, -opp]; | |
} | |
if (azim >= 180 && azim < 270) { | |
return [-opp, -adj]; | |
} | |
if (azim >= 270 && azim < 360) { | |
return [-adj, opp]; | |
} | |
return [0, 0] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment