13 #define _MATH_DEFINES_DEFINED 38 q[1] = q[2] = q[3] = 0.0;
66 result[0] = q1[0]*q2[0] - q1[1]*q2[1] - q1[2]*q2[2] - q1[3]*q2[3];
67 result[1] = q1[0]*q2[1] + q1[1]*q2[0] - q1[2]*q2[3] + q1[3]*q2[2];
68 result[2] = q1[0]*q2[2] + q1[1]*q2[3] + q1[2]*q2[0] - q1[3]*q2[1];
69 result[3] = q1[0]*q2[3] - q1[1]*q2[2] + q1[2]*q2[1] + q1[3]*q2[0];
80 result[0] = qc[0]*q2[0] + qc[1]*q2[1] + qc[2]*q2[2] + qc[3]*q2[3];
81 result[1] = qc[0]*q2[1] - qc[1]*q2[0] + qc[2]*q2[3] - qc[3]*q2[2];
82 result[2] = qc[0]*q2[2] - qc[1]*q2[3] - qc[2]*q2[0] + qc[3]*q2[1];
83 result[3] = qc[0]*q2[3] + qc[1]*q2[2] - qc[2]*q2[1] - qc[3]*q2[0];
94 result[0] = q1[0]*qc[0] + q1[1]*qc[1] + q1[2]*qc[2] + q1[3]*qc[3];
95 result[1] = -q1[0]*qc[1] + q1[1]*qc[0] + q1[2]*qc[3] - q1[3]*qc[2];
96 result[2] = -q1[0]*qc[2] - q1[1]*qc[3] + q1[2]*qc[0] + q1[3]*qc[1];
97 result[3] = -q1[0]*qc[3] + q1[1]*qc[2] - q1[2]*qc[1] + q1[3]*qc[0];
107 q_t d = (
q_t)1.0 / (q1[0] * q1[0] + q1[1] * q1[1] + q1[2] * q1[2] + q1[3] * q1[3]);
109 result[0] = (q1[0]*q2[0] + q1[1]*q2[1] + q1[2]*q2[2] + q1[3]*q2[3]) * d;
110 result[1] = (q1[0]*q2[1] - q1[1]*q2[0] - q1[2]*q2[3] + q1[3]*q2[2]) * d;
111 result[2] = (q1[0]*q2[2] + q1[1]*q2[3] - q1[2]*q2[0] - q1[3]*q2[1]) * d;
112 result[3] = (q1[0]*q2[3] - q1[1]*q2[2] + q1[2]*q2[1] - q1[3]*q2[0]) * d;
187 float sinang = 2 * (q[0] * q[2] - q[3] * q[1]);
188 if (sinang > 1.0
f) { sinang = 1.0f; }
189 if (sinang < -1.0
f) { sinang = -1.0f; }
191 theta[0] =
_ATAN2(2 * (q[0]*q[1] + q[2]*q[3]), 1 - 2 * (q[1]*q[1] + q[2]*q[2]));
192 theta[1] =
_ASIN (sinang);
193 theta[2] =
_ATAN2(2 * (q[0]*q[3] + q[1]*q[2]), 1 - 2 * (q[2]*q[2] + q[3]*q[3]));
197 float sinang = 2 * (q[0] * q[2] - q[3] * q[1]);
198 if (sinang > 1.0
f) { sinang = 1.0f; }
199 if (sinang < -1.0
f) { sinang = -1.0f; }
201 *phi =
_ATAN2( 2 * (q[0] * q[1] + q[2] * q[3]), 1 - 2 * (q[1] * q[1] + q[2] * q[2]) );
202 *theta =
_ASIN (sinang);
206 float sinang = 2 * (q[0] * q[2] - q[3] * q[1]);
207 if (sinang > 1.0
f) { sinang = 1.0f; }
208 if (sinang < -1.0
f) { sinang = -1.0f; }
210 *psi =
_ATAN2(2 * (q[0]*q[3] + q[1]*q[2]), 1 - 2 * (q[2]*q[2] + q[3]*q[3]));
220 f_t hphi = euler[0] * (
f_t)0.5;
221 f_t hthe = euler[1] * (
f_t)0.5;
222 f_t hpsi = euler[2] * (
f_t)0.5;
233 q[0] = chphi * chthe * chpsi + shphi * shthe * shpsi;
234 q[1] = shphi * chthe * chpsi - chphi * shthe * shpsi;
235 q[2] = chphi * shthe * chpsi + shphi * chthe * shpsi;
236 q[3] = chphi * chthe * shpsi - shphi * shthe * chpsi;
272 eul[1] = -lat - 0.5f *
C_PI_F;
301 eulned[1] = ((float)-lla[0]) - 0.5f *
C_PI_F;
302 eulned[2] = (float)lla[1];
342 return _ATAN2( m[1], m[0] );
370 m[3] = -spsi*cphi + cpsi*sthe*sphi;
371 m[4] = cpsi*cphi + spsi*sthe*sphi;
374 m[6] = spsi*sphi + cpsi*sthe*cphi;
375 m[7] = -cpsi*sphi + spsi*sthe*cphi;
428 m[1] = -spsi*cphi + cpsi*sthe*sphi;
429 m[4] = cpsi*cphi + spsi*sthe*sphi;
432 m[2] = spsi*sphi + cpsi*sthe*cphi;
433 m[5] = -cpsi*sphi + spsi*sthe*cphi;
449 euler[0] =
_ATAN2( m[5], m[8] );
450 euler[1] =
_ASIN( -m[2] );
451 euler[2] =
_ATAN2( m[1], m[0] );
468 f_t q0q1 = q[0]*q[1];
469 f_t q0q2 = q[0]*q[2];
470 f_t q0q3 = q[0]*q[3];
471 f_t q1q1 = q[1]*q[1];
472 f_t q1q2 = q[1]*q[2];
473 f_t q1q3 = q[1]*q[3];
474 f_t q2q2 = q[2]*q[2];
475 f_t q2q3 = q[2]*q[3];
476 f_t q3q3 = q[3]*q[3];
479 mat[0] = (
f_t)1.0 - (
f_t)2 * (q2q2 + q3q3);
480 mat[1] = (
f_t)2 * (q1q2 + q0q3);
481 mat[2] = (
f_t)2 * (q1q3 - q0q2);
483 mat[3] = (
f_t)2 * (q1q2 - q0q3);
484 mat[4] = (
f_t)1.0 - (
f_t)2 * (q1q1 + q3q3);
485 mat[5] = (
f_t)2 * (q2q3 + q0q1);
487 mat[6] = (
f_t)2 * (q1q3 + q0q2);
488 mat[7] = (
f_t)2 * (q2q3 - q0q1);
489 mat[8] = (
f_t)1.0 - (
f_t)2 * (q1q1 + q2q2);
493 f_t q0q1 = (
f_t)(q[0] * q[1]);
494 f_t q0q2 = (
f_t)(q[0] * q[2]);
495 f_t q0q3 = (
f_t)(q[0] * q[3]);
496 f_t q1q1 = (
f_t)(q[1] * q[1]);
497 f_t q1q2 = (
f_t)(q[1] * q[2]);
498 f_t q1q3 = (
f_t)(q[1] * q[3]);
499 f_t q2q2 = (
f_t)(q[2] * q[2]);
500 f_t q2q3 = (
f_t)(q[2] * q[3]);
501 f_t q3q3 = (
f_t)(q[3] * q[3]);
504 mat[0] = (
f_t)1.0 - (
f_t)2.0 * (q2q2 + q3q3);
505 mat[1] = (
f_t)2.0 * (q1q2 + q0q3);
506 mat[2] = (
f_t)2.0 * (q1q3 - q0q2);
508 mat[3] = (
f_t)2.0 * (q1q2 - q0q3);
509 mat[4] = (
f_t)1.0 - (
f_t)2.0 * (q1q1 + q3q3);
510 mat[5] = (
f_t)2.0 * (q2q3 + q0q1);
512 mat[6] = (
f_t)2.0 * (q1q3 + q0q2);
513 mat[7] = (
f_t)2.0 * (q2q3 - q0q1);
514 mat[8] = (
f_t)1.0 - (
f_t)2.0 * (q1q1 + q2q2);
531 q[0] = (
f_t)0.5 *
_SQRT((
f_t)1.0 + mat[0] + mat[4] + mat[8]);
533 d = (
f_t)1.0 / ((
f_t)4.0 * q[0]);
535 q[1] = d * (mat[5] - mat[7]);
536 q[2] = d * (mat[6] - mat[2]);
537 q[3] = d * (mat[1] - mat[3]);
572 f_t p = euler[0] * (
f_t)0.5;
574 f_t r = euler[2] * (
f_t)0.5;
610 sin_a =
_SQRT( (
f_t)1.0 - q[0] * q[0] );
615 d = (
f_t)1.0 / sin_a;
634 f_t t1 = 1 - 2 * (q[2]*q[2] + q[3]*q[2]);
635 f_t t2 = 2 * (q[1]*q[2] + q[0]*q[3]);
636 f_t err = 2 / ( t1*t1 + t2*t2 );
638 dq[0] = err * (q[3]*t1);
639 dq[1] = err * (q[2]*t1);
640 dq[2] = err * (q[1]*t1 + 2 * q[2]*t2);
641 dq[3] = err * (q[0]*t1 + 2 * q[3]*t2);
651 e[1] =
_ATAN2( -ned[2],
_SQRT( ned[0] * ned[0] + ned[1] * ned[1] ) );
652 e[2] =
_ATAN2( ned[1], ned[0] );
void quatDCM(const Quat_t q, Matrix3_t mat)
void DCMquat(const Matrix3_t mat, Quat_t q)
void quat2euler(const Quat_t q, Euler_t theta)
void vectorReferenceToBody(const Vector3_t v, const Euler_t rot, Vector3_t result)
void DCMeuler(const Matrix3_t m, Euler_t euler)
void quatConj(Quat_t result, const Quat_t q)
void eulerBodyToReference(const Euler_t e, const Euler_t rot, Euler_t result)
void cross_Vec3(Vector3 result, const Vector3 v1, const Vector3 v2)
void quat2psi(const Quat_t q, f_t *psi)
void psiDCM(const f_t psi, Matrix2_t m)
void mul_Mat3x3_Trans_Vec3x1(Vector3 result, const Matrix3 m, const Vector3 v)
void quatConjRot(Vector3_t result, const Quat_t q, const Vector3_t v)
void quatRotAxis(const Quat_t q, Vector3_t pqr)
void div_Quat_Quat(Quat_t result, const Quat_t q1, const Quat_t q2)
void quat_ecef2ned(float lat, float lon, float *qe2n)
f_t dot_Vec3_Vec3(const Vector3 v1, const Vector3 v2)
void mul_Mat3x3_Mat3x3(Matrix3 result, const Matrix3 m1, const Matrix3 m2)
void eulerNed(const Euler_t e, Vector3_t ned)
void quatW(const Euler_t euler, Matrix4_t mat)
void quat2phiTheta(const Quat_t q, f_t *phi, f_t *theta)
void mul_Quat_ConjQuat(Quat_t result, const Quat_t q1, const Quat_t qc)
void mul_Mat3x3_Vec3x1(Vector3 result, const Matrix3 m, const Vector3 v)
void euler2quat(const Euler_t euler, Quat_t q)
void quatdDCM(const Vector4d q, Matrix3_t mat)
void eulerReferenceToBody(const Euler_t e, const Euler_t rot, Euler_t result)
void quat_Vec3_Vec3(Quat_t result, const Vector3_t v1, const Vector3_t v2)
void eulerDCM(const Euler_t euler, Matrix3_t m)
void eulerWx(const Euler_t euler, Matrix3_t mat)
void qe2b2EulerNedEcef(Vector3 eul, const Vector4 qe2b, const Vector3d ecef)
void add_Vec3_Vec3(Vector3 result, const Vector3 v1, const Vector3 v2)
#define recipNorm_Vec3(v)
void qe2b2EulerNedLLA(Vector3 eul, const Vector4 qe2b, const Vector3d lla)
void ecef2lla(const double *Pe, double *LLA, const int Niter)
void mul_Quat_Quat(Quat_t result, const Quat_t q1, const Quat_t q2)
void mul_Vec3_X(Vector3 result, const Vector3 v, const f_t x)
void nedEuler(const Vector3_t ned, Euler_t e)
void dpsi_dq(const Quat_t q, Quat_t dq)
void eulerDCM_Trans(const Euler_t euler, Matrix3_t m)
void mul_Mat3x3_Mat3x3_Trans(Matrix3 result, const Matrix3 m1, const Matrix3 m2)
void mul_ConjQuat_Quat(Quat_t result, const Quat_t qc, const Quat_t q2)
void quatRot(Vector3_t result, const Quat_t q, const Vector3_t v)
void vectorBodyToReference(const Vector3_t v, const Euler_t rot, Vector3_t result)
void div_Vec4_X(Vector4 result, const Vector4 v, const f_t x)
void phiThetaDCM(const Euler_t euler, Matrix3_t m)