Skip to content

Instantly share code, notes, and snippets.

@davidcalhoun
Last active November 21, 2019 04:57
Show Gist options
  • Select an option

  • Save davidcalhoun/d3416a79c2b8a342e63b9a0b47371300 to your computer and use it in GitHub Desktop.

Select an option

Save davidcalhoun/d3416a79c2b8a342e63b9a0b47371300 to your computer and use it in GitHub Desktop.

Revisions

  1. davidcalhoun revised this gist Nov 21, 2019. 1 changed file with 11 additions and 4 deletions.
    15 changes: 11 additions & 4 deletions azimElevToXY.js
    Original file line number Diff line number Diff line change
    @@ -13,20 +13,27 @@ const getXY = (azim, elev, canvasSize) => {
    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 [adj, opp];
    return [opp, adj];
    }

    if (azim >= 90 && azim < 180) {
    return [-opp, adj];
    return [adj, -opp];
    }

    if (azim >= 180 && azim < 270) {
    return [-adj, -opp];
    return [-opp, -adj];
    }

    if (azim >= 270 && azim < 360) {
    return [opp, -adj];
    return [-adj, opp];
    }

    return [0, 0]
  2. davidcalhoun revised this gist Nov 21, 2019. 1 changed file with 7 additions and 5 deletions.
    12 changes: 7 additions & 5 deletions azimElevToXY.js
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,17 @@
    const elevToHypLength = (elev, max) => {
    return max - (max * elev) / 89.99999999;
    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 angleRads = deg2rad(azim % 90);
    const angle = deg2rad(azim % 90);

    const opp = Math.sin(angleRads) * hyp;
    const adj = Math.cos(angleRads) * hyp;
    const opp = toFixedFloat(Math.sin(angle) * hyp, 2);
    const adj = toFixedFloat(Math.cos(angle) * hyp, 2);

    if (azim >= 0 && azim < 90) {
    return [adj, opp];
  3. davidcalhoun revised this gist Nov 21, 2019. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions azimElevToXY.js
    Original file line number Diff line number Diff line change
    @@ -11,19 +11,19 @@ const getXY = (azim, elev, canvasSize) => {
    const opp = Math.sin(angleRads) * hyp;
    const adj = Math.cos(angleRads) * hyp;

    if (azim >= 0 && azim <= 89.9999999) {
    if (azim >= 0 && azim < 90) {
    return [adj, opp];
    }

    if (azim >= 90 && azim <= 179.9999999) {
    if (azim >= 90 && azim < 180) {
    return [-opp, adj];
    }

    if (azim >= 180 && azim <= 269.9999999) {
    if (azim >= 180 && azim < 270) {
    return [-adj, -opp];
    }

    if (azim >= 270 && azim <= 359.9999999) {
    if (azim >= 270 && azim < 360) {
    return [opp, -adj];
    }

  4. davidcalhoun revised this gist Nov 21, 2019. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions azimElevToXY.js
    Original file line number Diff line number Diff line change
    @@ -6,10 +6,10 @@ const deg2rad = deg => (Math.PI * 2 * deg) / 360;

    const getXY = (azim, elev, canvasSize) => {
    const hyp = elevToHypLength(elev, canvasSize / 2);
    const angle = deg2rad(azim % 90);
    const angleRads = deg2rad(azim % 90);

    const opp = Math.sin(angle) * hyp;
    const adj = Math.cos(angle) * hyp;
    const opp = Math.sin(angleRads) * hyp;
    const adj = Math.cos(angleRads) * hyp;

    if (azim >= 0 && azim <= 89.9999999) {
    return [adj, opp];
  5. davidcalhoun revised this gist Nov 21, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions azimElevToXY.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    const elevToHypLength = (elev, canvasSize) => {
    return canvasSize - (canvasSize * elev) / 89.99999999;
    const elevToHypLength = (elev, max) => {
    return max - (max * elev) / 89.99999999;
    }

    const deg2rad = deg => (Math.PI * 2 * deg) / 360;
  6. davidcalhoun renamed this gist Nov 21, 2019. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  7. davidcalhoun created this gist Nov 21, 2019.
    31 changes: 31 additions & 0 deletions satellite azim,elev to cartesian coords
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    const elevToHypLength = (elev, canvasSize) => {
    return canvasSize - (canvasSize * elev) / 89.99999999;
    }

    const deg2rad = deg => (Math.PI * 2 * deg) / 360;

    const getXY = (azim, elev, canvasSize) => {
    const hyp = elevToHypLength(elev, canvasSize / 2);
    const angle = deg2rad(azim % 90);

    const opp = Math.sin(angle) * hyp;
    const adj = Math.cos(angle) * hyp;

    if (azim >= 0 && azim <= 89.9999999) {
    return [adj, opp];
    }

    if (azim >= 90 && azim <= 179.9999999) {
    return [-opp, adj];
    }

    if (azim >= 180 && azim <= 269.9999999) {
    return [-adj, -opp];
    }

    if (azim >= 270 && azim <= 359.9999999) {
    return [opp, -adj];
    }

    return [0, 0]
    }