64 #include "utility/matrix/Vector.h" 65 #include "utility/matrix/Matrix.h" 83 mData[0] = mData[1] = mData[2] = 0.0;
107 mData[0] = v(0 + index);
108 mData[1] = v(1 + index);
109 mData[2] = v(2 + index);
118 mData[0] = other.mData[0];
119 mData[1] = other.mData[1];
120 mData[2] = other.mData[2];
131 if (
this != &other) {
132 mData[0] = other.mData[0];
133 mData[1] = other.mData[1];
134 mData[2] = other.mData[2];
145 inline const T
x()
const {
return mData[0]; }
151 inline const T
y()
const {
return mData[1]; }
157 inline const T
z()
const {
return mData[2]; }
192 mData[0] * mData[0] +
193 mData[1] * mData[1] +
229 mData[0] * b.mData[0] +
230 mData[1] * b.mData[1] +
231 mData[2] * b.mData[2];
242 c.mData[0] = mData[1] * b.mData[2] - mData[2] * b.mData[1];
243 c.mData[1] = mData[2] * b.mData[0] - mData[0] * b.mData[2];
244 c.mData[2] = mData[0] * b.mData[1] - mData[1] * b.mData[0];
252 mData[0] += b.mData[0];
253 mData[1] += b.mData[1];
254 mData[2] += b.mData[2];
266 mData[0] -= b.mData[0];
267 mData[1] -= b.mData[1];
268 mData[2] -= b.mData[2];
278 inline void operator *= (T b)
292 inline void operator /= (T b)
318 template<
class TStream,
class T>
319 inline TStream& operator << (TStream& s, const ASDVector3<T>& v)
321 return (s <<
"(" << v.x() <<
", " << v.y() <<
", " << v.z() <<
")");
379 if (
this != &other) {
394 inline const T
x()
const {
return mX; }
400 inline const T
y()
const {
return mY; }
406 inline const T
z()
const {
return mZ; }
412 inline const T
w()
const {
return mW; }
423 return mX * mX + mY * mY + mZ * mZ + mW * mW;
443 if (n > 0.0 && n != 1.0) {
473 template<
class TMatrix3x3>
476 R(0, 0) = 2.0 * (mW * mW + mX * mX - 0.5);
477 R(0, 1) = 2.0 * (mX * mY - mW * mZ);
478 R(0, 2) = 2.0 * (mX * mZ + mW * mY);
480 R(1, 0) = 2.0 * (mY * mX + mW * mZ);
481 R(1, 1) = 2.0 * (mW * mW + mY * mY - 0.5);
482 R(1, 2) = 2.0 * (mY * mZ - mX * mW);
484 R(2, 0) = 2.0 * (mZ * mX - mW * mY);
485 R(2, 1) = 2.0 * (mZ * mY + mW * mX);
486 R(2, 2) = 2.0 * (mW * mW + mZ * mZ - 0.5);
512 T vNorm = xx * xx + yy * yy + zz * zz;
521 vNorm = std::sqrt(vNorm);
523 T mult = (vNorm < ww) ? (2.0 / vNorm * std::asin(vNorm)) : (2.0 / vNorm * std::acos(ww));
538 template<
class TVector3>
541 toRotationVector(v(0), v(1), v(2));
555 template<
class TVector3_A,
class TVector3_B>
559 b(0) = 2.0 * (mY * a(2) - mZ * a(1));
560 b(1) = 2.0 * (mZ * a(0) - mX * a(2));
561 b(2) = 2.0 * (mX * a(1) - mY * a(0));
564 T c0 = mY * b(2) - mZ * b(1);
565 T c1 = mZ * b(0) - mX * b(2);
566 T c2 = mX * b(1) - mY * b(0);
569 b(0) = a(0) + b(0) * mW + c0;
570 b(1) = a(1) + b(1) * mW + c1;
571 b(2) = a(2) + b(2) * mW + c2;
584 template<
class TVector3>
588 T b0 = 2.0 * (mY * a(2) - mZ * a(1));
589 T b1 = 2.0 * (mZ * a(0) - mX * a(2));
590 T b2 = 2.0 * (mX * a(1) - mY * a(0));
593 T c0 = mY * b2 - mZ * b1;
594 T c1 = mZ * b0 - mX * b2;
595 T c2 = mX * b1 - mY * b0;
598 a(0) += b0 * mW + c0;
599 a(1) += b1 * mW + c1;
600 a(2) += b2 * mW + c2;
624 T sqnorm = x * x + y * y + z *
z;
628 if (sqnorm > 0.0 && sqnorm != 1.0) {
629 T
norm = std::sqrt(sqnorm);
635 T halfAngle = radians * 0.5;
637 T s = std::sin(halfAngle);
638 T q0 = std::cos(halfAngle);
655 T rModulus = rx * rx + ry * ry + rz * rz;
659 if (rModulus != 1.0) {
660 rModulus = std::sqrt(rModulus);
666 T halfAngle = rModulus * 0.5;
668 T q0 = std::cos(halfAngle);
669 T s = std::sin(halfAngle);
686 template<
class TVector3>
703 template<
class TMatrix3x3>
711 if ((tr > xx) && (tr > yy) && (tr > zz))
713 T S = std::sqrt(tr + 1.0) * 2.0;
716 (m(2, 1) - m(1, 2)) / S,
717 (m(0, 2) - m(2, 0)) / S,
718 (m(1, 0) - m(0, 1)) / S
721 else if ((xx > yy) && (xx > zz))
723 T S = std::sqrt(1.0 + xx - yy - zz) * 2.0;
725 (m(2, 1) - m(1, 2)) / S,
727 (m(0, 1) + m(1, 0)) / S,
728 (m(0, 2) + m(2, 0)) / S
733 T S = std::sqrt(1.0 + yy - xx - zz) * 2.0;
735 (m(0, 2) - m(2, 0)) / S,
736 (m(0, 1) + m(1, 0)) / S,
738 (m(1, 2) + m(2, 1)) / S
743 T S = std::sqrt(1.0 + zz - xx - yy) * 2.0;
745 (m(1, 0) - m(0, 1)) / S,
746 (m(0, 2) + m(2, 0)) / S,
747 (m(1, 2) + m(2, 1)) / S,
776 a.
w() * b.
w() - a.
x() * b.
x() - a.
y() * b.
y() - a.
z() * b.
z(),
777 a.
w() * b.
x() + a.
x() * b.
w() + a.
y() * b.
z() - a.
z() * b.
y(),
778 a.
w() * b.
y() + a.
y() * b.
w() + a.
z() * b.
x() - a.
x() * b.
z(),
779 a.
w() * b.
z() + a.
z() * b.
w() + a.
x() * b.
y() - a.
y() * b.
x()
789 template<
class TStream,
class T>
790 inline TStream& operator << (TStream& s, const ASDQuaternion<T>& q)
792 return (s <<
"[(" << q.x() <<
", " << q.y() <<
", " << q.z() <<
"), " << q.w() <<
"]");
Float vector abstraction.
Definition: Vector.h:94
ASDVector3(const Vector &v, size_t index=0)
Creates a ASDVector3 from a Vector starting from index.
Definition: ASDMath.h:105
T squaredNorm() const
Returns the squared norm this vector.
Definition: ASDMath.h:189
ASDVector3(T x, T y, T z)
Creates a ASDVector3 from its coefficients.
Definition: ASDMath.h:92
T & operator[](size_t i)
Returns the i-th coefficient of this vector.
Definition: ASDMath.h:181
ASDQuaternion(const ASDQuaternion &other)
Creates a ASDQuaternion from another ASDQuaternion.
Definition: ASDMath.h:363
ASDQuaternion(T w, T x, T y, T z)
Creates a ASDQuaternion from its coefficients.
Definition: ASDMath.h:351
void toRotationMatrix(TMatrix3x3 &R) const
Constructs a Rotation Matrix from this ASDQuaternion.
Definition: ASDMath.h:474
ASDVector3()
Creates a Zero ASDVector3.
Definition: ASDMath.h:81
const T z() const
Returns the Z coefficient of this quaternion.
Definition: ASDMath.h:406
void toRotationVector(T &rx, T &ry, T &rz) const
Extracts the Rotation Vector from this ASDQuaternion.
Definition: ASDMath.h:495
const T y() const
Returns the Y coefficient of this quaternion.
Definition: ASDMath.h:400
const T z() const
Returns the Z coefficient of this vector.
Definition: ASDMath.h:157
T operator[](size_t i) const
Returns the i-th coefficient of this vector.
Definition: ASDMath.h:175
ASDQuaternion conjugate() const
Returns the Conjugate of this ASDQuaternion, which represents the opposite rotation.
Definition: ASDMath.h:456
void toRotationVector(TVector3 &v) const
Extracts the Rotation Vector from this ASDQuaternion The vector type is the template parameter...
Definition: ASDMath.h:539
const T norm() const
Returns the norm of this quaternion.
Definition: ASDMath.h:431
static ASDQuaternion FromRotationVector(const TVector3 &v)
Returns a ASDQuaternion from a rotation vector.
Definition: ASDMath.h:687
void rotateVector(const TVector3_A &a, TVector3_B &b) const
Rotates a vector using this quaternion.
Definition: ASDMath.h:556
static ASDQuaternion FromRotationVector(T rx, T ry, T rz)
Returns a ASDQuaternion from a rotation vector.
Definition: ASDMath.h:653
T normalize()
makes this vector a unit vector.
Definition: ASDMath.h:210
T dot(const ASDVector3 &b) const
Returns the dot product this vector with another vector.
Definition: ASDMath.h:226
T & operator()(size_t i)
Returns the i-th coefficient of this vector.
Definition: ASDMath.h:169
ASDVector3 cross(const ASDVector3 &b) const
Returns the cross product this vector with another vector.
Definition: ASDMath.h:239
T norm() const
Returns the norm this vector.
Definition: ASDMath.h:201
void normalize()
Makes this ASDQuaternion a Unit ASDQuaternion.
Definition: ASDMath.h:440
ASDVector3(const ASDVector3 &other)
Creates a ASDVector3 from another ASDVector3.
Definition: ASDMath.h:116
const T x() const
Returns the X coefficient of this vector.
Definition: ASDMath.h:145
static ASDQuaternion FromAxisAngle(T x, T y, T z, T radians)
Returns a ASDQuaternion that represents a rotation of an angle 'radians' around the axis (x...
Definition: ASDMath.h:622
Open source finite element program for structural analysis.
Definition: ContinuaReprComponent.h:35
ASDVector3 & operator=(const ASDVector3 &other)
Copies a ASDVector3.
Definition: ASDMath.h:129
const T squaredNorm() const
Returns the squared norm of this quaternion.
Definition: ASDMath.h:421
ASDQuaternion()
Creates a Zero ASDQuaternion.
Definition: ASDMath.h:336
const T x() const
Returns the X coefficient of this quaternion.
Definition: ASDMath.h:394
static ASDQuaternion FromRotationMatrix(const TMatrix3x3 &m)
Returns a ASDQuaternion from a Rotation Matrix.
Definition: ASDMath.h:704
T operator()(size_t i) const
Returns the i-th coefficient of this vector.
Definition: ASDMath.h:163
static ASDQuaternion Identity()
Returns the Identity ASDQuaternion (i.e.
Definition: ASDMath.h:609
ASDQuaternion A simple fixed size 3D vector.
Definition: ASDMath.h:72
const T y() const
Returns the Y coefficient of this vector.
Definition: ASDMath.h:151
void rotateVector(TVector3 &a) const
Rotates a vector using this quaternion.
Definition: ASDMath.h:585
ASDQuaternion A simple class that implements the main features of quaternion algebra.
Definition: ASDMath.h:328
const T w() const
Returns the W coefficient of this quaternion.
Definition: ASDMath.h:412