Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
}
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();
}
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();
}
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));
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;
}
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);
}
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);
}
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);
}
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);
}
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);
}