How to use quaternion - 10 common examples

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
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));
        
        // fromAxisAngle imprecis ? 
        // const rotatedCenter = center.mul(angleFrom, angle);

        // const originBack = rotatedCenter.inverse().rotateVector(xpt3d);
        // console.log("originBack is ", originBack[0] - x3d, originBack[1] - y3d, originBack[2] - z3d);

        return rotatedCenter;
    }
github pludov / mobindi / ui / src / SkyAlgorithms / SkyProjection.ts View on Github external
public static getEQ3DToALTAZ3DQuaternion(msTime: number, geoCoords: {lat:number, long:number})
    {
        /*
         * In this projection, north pole is toward z axis (0,0,1). and ra=0 point to the x axis
         */
        const zenithRaDeg = SkyProjection.getLocalSideralTime(msTime, geoCoords.long);
        const q1 = Quaternion.fromAxisAngle([0,0,1], deg2rad(-zenithRaDeg));

        // Now rotate the pole according to latitude
        const q2 = Quaternion.fromAxisAngle([0,1,0], deg2rad(geoCoords.lat));

        return q2.mul(q1).neg();
    }
github pludov / mobindi / ui / src / SkyAlgorithms / SkyProjection.ts View on Github external
public static getEQ3DToALTAZ3DQuaternion(msTime: number, geoCoords: {lat:number, long:number})
    {
        /*
         * In this projection, north pole is toward z axis (0,0,1). and ra=0 point to the x axis
         */
        const zenithRaDeg = SkyProjection.getLocalSideralTime(msTime, geoCoords.long);
        const q1 = Quaternion.fromAxisAngle([0,0,1], deg2rad(-zenithRaDeg));

        // Now rotate the pole according to latitude
        const q2 = Quaternion.fromAxisAngle([0,1,0], deg2rad(geoCoords.lat));

        return q2.mul(q1).neg();
    }
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;
    }
github pludov / mobindi / ui / src / SkyAlgorithms / SkyProjection.ts View on Github external
public static getALTAZ3DMountCorrectionQuaternion(axe1AltAz: number[], axe2AltAz : number[])
    {
        const cleanAz = Quaternion.fromAxisAngle([1,0,0], deg2rad(axe1AltAz[1]));
        const applyAlt = Quaternion.fromAxisAngle([0,1,0], deg2rad(axe2AltAz[0] - axe1AltAz[0]));
        const resetAz = Quaternion.fromAxisAngle([1,0,0], deg2rad(-axe2AltAz[1]));

        return resetAz.mul(applyAlt).mul(cleanAz);
    }
github pludov / mobindi / ui / src / SkyAlgorithms / SkyProjection.ts View on Github external
public static getALTAZ3DMountCorrectionQuaternion(axe1AltAz: number[], axe2AltAz : number[])
    {
        const cleanAz = Quaternion.fromAxisAngle([1,0,0], deg2rad(axe1AltAz[1]));
        const applyAlt = Quaternion.fromAxisAngle([0,1,0], deg2rad(axe2AltAz[0] - axe1AltAz[0]));
        const resetAz = Quaternion.fromAxisAngle([1,0,0], deg2rad(-axe2AltAz[1]));

        return resetAz.mul(applyAlt).mul(cleanAz);
    }
github pludov / mobindi / ui / src / SkyAlgorithms / SkyProjection.ts View on Github external
public static getEQ3DQuaternion(raDec: number[])
    {
        const decQ = Quaternion.fromAxisAngle([0,1,0], deg2rad(-raDec[1]));
        const raQ = Quaternion.fromAxisAngle([0,0,1], deg2rad(raDec[0]));
        return raQ.mul(decQ);
    }
github pludov / mobindi / ui / src / SkyAlgorithms / SkyProjection.ts View on Github external
public static getALTAZ3DMountCorrectionQuaternion(axe1AltAz: number[], axe2AltAz : number[])
    {
        const cleanAz = Quaternion.fromAxisAngle([1,0,0], deg2rad(axe1AltAz[1]));
        const applyAlt = Quaternion.fromAxisAngle([0,1,0], deg2rad(axe2AltAz[0] - axe1AltAz[0]));
        const resetAz = Quaternion.fromAxisAngle([1,0,0], deg2rad(-axe2AltAz[1]));

        return resetAz.mul(applyAlt).mul(cleanAz);
    }
github pludov / mobindi / ui / src / SkyAlgorithms / SkyProjection.ts View on Github external
public static getEQ3DQuaternion(raDec: number[])
    {
        const decQ = Quaternion.fromAxisAngle([0,1,0], deg2rad(-raDec[1]));
        const raQ = Quaternion.fromAxisAngle([0,0,1], deg2rad(raDec[0]));
        return raQ.mul(decQ);
    }

quaternion

A rotation library using quaternions

MIT
Latest version published 1 year ago

Package Health Score

51 / 100
Full package analysis