55 std::cout <<
"Axis=" << axis <<
" Angle=" << angle << std::endl;
73 angle = 2.0 * std::acos(
w_);
80 double xy = 2.0 * (
x_ *
y_ -
w_ *
z_);
81 double xz = 2.0 * (
w_ *
y_ +
x_ *
z_);
82 double yx = 2.0 * (
x_ *
y_ +
w_ *
z_);
84 double yz = 2.0 * (
y_ * z_ -
w_ *
x_);
85 double zx = 2.0 * (
x_ * z_ -
w_ *
y_);
86 double zy = 2.0 * (
w_ *
x_ +
y_ *
z_);
88 return Matrix3D(xx, xy, xz, yx, yy, yz, zx, zy, zz);
121 Vec3D theta = 0.5 * omega * timeStep;
124 if (thetaMagSq * thetaMagSq / 24.0 < 1e-10)
126 std::cout <<
"Warning small rotation, needs additional checking" << std::endl;
127 deltaQ.
w_ = 1.0 - 0.5 * thetaMagSq;
128 s = 1.0 - thetaMagSq / 6.0;
132 double thetaMag = std::sqrt(thetaMagSq);
136 deltaQ.
x_ = theta.
X * s;
137 deltaQ.
y_ = theta.
Y * s;
138 deltaQ.
z_ = theta.
Z * s;
140 *
this = deltaQ * *
this;
145 double rotY, rotZ, rotX;
146 double sqrtX =
x_ *
x_;
147 double sqrtY =
y_ *
y_;
148 double sqrtZ =
z_ *
z_;
149 double sqrtW =
w_ *
w_;
150 double unit = sqrtX + sqrtY + sqrtZ + sqrtW;
151 double test = x_ * y_ + z_ *
w_;
152 if (test > 0.499999 * unit)
154 rotY = 2.0 * std::atan2(x_, w_);
158 else if (test < -0.499999 * unit)
160 rotY = -2.0 * atan2(x_, w_);
166 rotY = atan2(2.0 * y_ * w_ - 2.0 * x_ * z_, sqrtX - sqrtY - sqrtZ + sqrtW);
167 rotZ = asin(2.0 * test / unit);
168 rotX = atan2(2.0 * x_ * w_ - 2.0 * y_ * z_, -sqrtX + sqrtY - sqrtZ + sqrtW);
170 return Vec3D(rotX, rotY, rotZ);
175 os << q.
x_ <<
" " << q.
y_ <<
" " << q.
z_ <<
" " << q.
w_;
void getAxisAndAngle(Vec3D &axis, double &angle) const
Returns the orientation as represented by a rotation around an axis.
static Mdouble getLengthSquared(const Vec3D &a)
Calculates the squared length of a Vec3D: .
Vec3D get3DAngles() const
Constructs a representation of the quarternion using 3 rotations in the lab x-y-z sequence...
Mdouble X
the vector components
std::ostream & operator<<(std::ostream &os, const Quarternion &q)
void normalize()
Makes this Vec3D unit length.
void reset()
Resets a the Quarternion.
Quarternion operator*(const Quarternion &other) const
Multiplication operator.
Quarternion()
Constructs a basic Quarternion.
std::istream & operator>>(std::istream &is, Quarternion &q)
Matrix3D getRotationMatrix() const
Implementation of a 3D matrix.
Implementation of a 3D vector (by Vitaliy).
void normalise()
Normalises the Quarternion.
void integrate(const Vec3D &omega, double timeStep)
Integration of the Quarternion using rotational velocity and timestep.