Skip to content

Instantly share code, notes, and snippets.

@raybellis
Last active October 7, 2024 14:45
Show Gist options
  • Select an option

  • Save raybellis/d6d06ac5927b5cedcea04245586d807f to your computer and use it in GitHub Desktop.

Select an option

Save raybellis/d6d06ac5927b5cedcea04245586d807f to your computer and use it in GitHub Desktop.

Revisions

  1. raybellis revised this gist Oct 7, 2024. No changes.
  2. raybellis renamed this gist Oct 7, 2024. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. raybellis revised this gist Oct 7, 2024. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions geometry.js
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@ const p2 = { x: 59197011, y: 21399618, z: 42913136384, sx: 254, sy: 664 };
    const p3 = { x: 6735114, y: 33773393, z: 4287356928 , sx: 808, sy: 65 };
    const p4 = { x: 26245172, y: 42146958, z: 4293136384, sx: 495, sy: 212 };

    function project(x, y, z) {
    function project({x, y, z}) {

    // use p4 as the origin
    x -= p4.x;
    @@ -41,7 +41,7 @@ function project(x, y, z) {
    return [~~sx, ~~sy];
    }

    console.log('P1 = ', project(p1.x, p1.y, p1.z));
    console.log('P2 = ', project(p2.x, p2.y, p2.z));
    console.log('P3 = ', project(p3.x, p3.y, p3.z));
    console.log('P4 = ', project(p4.x, p4.y, p4.z));
    console.log('P1 = ', project(p1));
    console.log('P2 = ', project(p2));
    console.log('P3 = ', project(p3));
    console.log('P4 = ', project(p4));
  4. raybellis created this gist Oct 7, 2024.
    47 changes: 47 additions & 0 deletions geometry.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    const p1 = { x: 59197011, y: 42146958, z: 42913136384, sx: 24, sy: 470 };
    const p2 = { x: 59197011, y: 21399618, z: 42913136384, sx: 254, sy: 664 };
    const p3 = { x: 6735114, y: 33773393, z: 4287356928 , sx: 808, sy: 65 };
    const p4 = { x: 26245172, y: 42146958, z: 4293136384, sx: 495, sy: 212 };

    function project(x, y, z) {

    // use p4 as the origin
    x -= p4.x;
    y -= p4.y;
    z -= p4.z;

    // and start screen coordinate calculations from there too
    let sx = p4.sx;
    let sy = p4.sy;

    // calculate how much sx / sy change per unit change of x
    // by looking at the differences between p1 and p4 where
    // only the X coordinate changes
    const xscale_x = (p4.sx - p1.sx) / (p4.x - p1.x);
    const xscale_y = (p4.sy - p1.sy) / (p4.x - p1.x);

    sx += x * xscale_x;
    sy += x * xscale_y;

    // calculate how much sx / sy change per unit change of y
    // by looking at the differences between p2 and p1 where
    // only the Y coordinate changes
    const yscale_x = (p2.sx - p1.sx) / (p2.y - p1.y);
    const yscale_y = (p2.sy - p1.sy) / (p2.y - p1.y);

    sx += y * yscale_x;
    sy += y * yscale_y;

    // adjustment of screen Y coordinate based on Z axis is TBD
    // since current coordinates appear incorrect and because
    // we have no (X, Y) invariant coordinates to calculate
    // from. The math above indicates that the X coordinate
    // of P3 *should* be 866 instead of the given 808

    return [~~sx, ~~sy];
    }

    console.log('P1 = ', project(p1.x, p1.y, p1.z));
    console.log('P2 = ', project(p2.x, p2.y, p2.z));
    console.log('P3 = ', project(p3.x, p3.y, p3.z));
    console.log('P4 = ', project(p4.x, p4.y, p4.z));