How to use the quaternion.fromBetweenVectors function in quaternion

To help you get started, we’ve selected a few quaternion examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pludov / mobindi / ui / src / SkyAlgorithms / SkyProjection.ts View on Github external
public getIMG3DToEQ3DQuaternion(xy: number[]) {
        const x = (xy[0] - this.centerx) * this.pixelRad;
        const y = (xy[1] - this.centery) * this.pixelRad;

        const z3d = 1.0 / Math.sqrt(y * y + x * x + 1.0);
        const x3d = x * z3d;
        const y3d = y * z3d;

        // Center of the quaternion
        const pt3d = this.invertedTransform.convert([x3d, y3d, z3d]);

        let center =  Quaternion.fromBetweenVectors([0,0,1], pt3d);

        const toLocal = center.inverse();
        // const xpt3d = this.invertedTransform.convert([1000, y3d, z3d]);
        // const localxpt3d = toLocal.rotateVector(xpt3d);

        // const angle = Math.atan2(localxpt3d[1] - y3d, localxpt3d[0] - x3d);
        // const angleFrom = Quaternion.fromBetweenVectors([x3d + 1000, y3d, z3d], [localxpt3d[0] , localxpt3d[1], localxpt3d[2]]);

        const xpt3d = this.invertedTransform.convert([1, 0, 0]);
        const localxpt3d = toLocal.rotateVector(xpt3d);

        const angle = Math.atan2(localxpt3d[1], localxpt3d[0]);
        // const angleFrom = Quaternion.fromBetweenVectors([1, 0, 0], localxpt3d);

        const rotatedCenter = center.mul(Quaternion.fromAxisAngle([0, 0, 1], angle));
github pludov / mobindi / ui / src / SkyAlgorithms / SkyProjection.ts View on Github external
}
        }
        else {
            if (m00 < -m11) {
                t = 1 -m00 -m11 + m22;
                q = Quaternion( m20+m02, m12+m21, t, m01-m10 );
            }
            else {
                t = 1 + m00 + m11 + m22;
                q = Quaternion( m12-m21, m20-m02, m01-m10, t );
            }
        }
        q = q .scale(0.5 / Math.sqrt(t));
        

        let axisQuat = Quaternion.fromBetweenVectors([0,0,1],[1,0,0]);

        const quat = Quaternion.fromAxisAngle([0,1,0], Math.PI/2)
                    .mul(q.inverse())
                    .mul(axisQuat);
        return quat;
    }

quaternion

A rotation library using quaternions

MIT
Latest version published 21 days ago

Package Health Score

65 / 100
Full package analysis