let it leave me like a long breath

let it dissipate or fade in the background

Dec. 5th, 2023

Profile

xax: purple-orange {11/3 knotwork star, pointed down (Default)
howling howling howling

Nav

  • Recent Entries
  • Archive
  • Reading
  • Tags
  • Memories
  • Profile

Tags

  • art - 2 uses
  • asteroid garden - 4 uses
  • code - 19 uses
  • demos - 1 use
  • dreams - 5 uses
  • ff7 fangame - 23 uses
  • fic prompts - 13 uses
  • gamedev challenge - 82 uses
  • hell game - 76 uses
  • nanowrimo - 11 uses
  • plants - 9 uses
  • process - 52 uses
  • programming - 51 uses
  • screenshots - 5 uses
  • writing log - 83 uses

May 2025

S M T W T F S
    123
45678 910
1112131415 1617
18192021222324
25262728293031
    • Previous Day
    • |
    • Next Day

    Dec. 5th, 2023

  • xax: purple-orange {11/3 knotwork star, pointed down (Default)
    Tags:
    • code,
    • programming
    posted @ 03:33 pm

    anyway here's the actual math if anybody wants to help me with this :V

    so i have some stored vertices for a prism going from 0,0,0 to 0,1,0. it's a rectangular prism 0.2 units thick and 1 unit long. fine, whatever.

    i want to reposition it so that it's actually positioned between two arbitrary points, p1 and p2. the way i'm doing that currently is like this:

    const at = (vec) => {
        const base = new Point3d (0,1,0);
        const axis = base.cross (vec.normalize());
    
        const angle = base.vectorAngle (vec);
    
        return axisAngle (axis, angle).multiply(scale (1, vec.magnitude(), 1));
    };

    where

    
    // returns angle in range 0..pi
    Point3d.prototype.vectorAngle = function (vec) {
        const this_ = this.normalize();
        const vec_ = vec.normalize();
        const n = vec_.cross(this_);
    
        return Math.atan2 (n.dot(n), this_.dot (vec_));
    };
    
    function axisAngle (axis, angle) {
        const sin_a = Math.sin (angle / 2);
        const cos_a = Math.cos (angle / 2);
        const axis_ = axis.normalize();
    
        return new Quaternion (axis_.x * sin_a, axis_.y * sin_a, axis_.z * sin_a, cos_a).normalize().toMatrix();
    }

    (i mean i'm not sure that all the quaternion & vector math is right but if i got cross products and quaternion->matrix code wrong i assume it would've cropped up before now)

    the fundamental thing is that i assume given two points like...
    let a = new Point3d (0,1,0).normalize();
    let b = new Point3d (1,2,3).normalize();

    then something like m = axisAngle (a.cross(b), a.vectorAngle(b)) should generate a matrix where m.multiplyVector(a, 1) equals b

    when in fact!!! if i do it with this code & these values i get
    b = Object { x: 0.2672612419124244, y: 0.5345224838248488, z: 0.8017837257372732 }
    
    m.multiplyVector(a, 1) = Object { x: 0.25318484177091666, y: 0.5991446895152781, z: 0.7595545253127499 }


    so very close but not actually the same. it seems like they should be the same.

    (also there's a secondary issue where i know... the at code there is underspecified, because you need some spare coordinate axes to determine how points in the plane of vec get positioned, since all you have so far is the y axis transform; you need at least an x/z one too. i think this is a separate issue than the above but to be fair i haven't tried to fix it yet.)

    • Add Memory
    • Share This Entry
    • Link
    • 0 comments
    • Reply
    • Previous Day
    • |
    • Next Day
Page generated Sep. 21st, 2025 12:06 am
Powered by Dreamwidth Studios

Style Credit

  • Style: (No Theme) for vertical