src/kalidokit/utils/vector.js
//find 2D angle between 3 points in space
find 2D angle between 3 points in space
find 2D angle between 3 points in space
static angleBetween3DCoords(a, b, c) {
        if (a instanceof Vector === false) {
            a = new Vector(a);
            b = new Vector(b);
            c = new Vector(c);
        }
        const v1 = a.subtract(b);
        const v2 = c.subtract(b);
        const v1norm = v1.unit();
        const v2norm = v2.unit();
        const dotProducts = v1norm.dot(v2norm);
        const angle = Math.acos(dotProducts);
        return Vector.normalizeRadians(angle);
    }
static angleBetween3DCoords ( a , b , c ) { if ( a instanceof Vector === false ) { a = new Vector ( a ) ; b = new Vector ( b ) ; c = new Vector ( c ) ; } const v1 = a . subtract ( b ) ; const v2 = c . subtract ( b ) ; const v1norm = v1 . unit ( ) ; const v2norm = v2 . unit ( ) ; const dotProducts = v1norm . dot ( v2norm ) ; const angle = Math . acos ( dotProducts ) ; return Vector . normalizeRadians ( angle ) ; }
find 2D angle between 3 points in space
find 2D angle between 3 points in space
// Calculate vector between points 1 and 2 // Calculate vector between points 2 and 3 // The dot product of vectors v1 & v2 is a function of the cosine of the // angle between them (it's scaled by the product of their magnitudes). // Calculate the dot products of vectors v1 and v2 // Extract the angle from the dot products // return single angle Normalized to 1