Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
satellite azim,elev to cartesian coords
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
You can’t perform that action at this time.