18 #ifndef ION_MATH_ROTATION_H_
19 #define ION_MATH_ROTATION_H_
46 quat_.
Set(static_cast<T>(0), static_cast<T>(0), static_cast<T>(0),
57 return quat_[3] ==
static_cast<T>(1) ||
58 quat_[3] == static_cast<T>(-1);
114 return Rotation(-r.quat_[0], -r.quat_[1], -r.quat_[2], r.quat_[3]);
122 qr[3] * qt[0] + qr[0] * qt[3] + qr[2] * qt[1] - qr[1] * qt[2],
123 qr[3] * qt[1] + qr[1] * qt[3] + qr[0] * qt[2] - qr[2] * qt[0],
124 qr[3] * qt[2] + qr[2] * qt[3] + qr[1] * qt[0] - qr[0] * qt[1],
125 qr[3] * qt[3] - qr[0] * qt[0] - qr[1] * qt[1] - qr[2] * qt[2]));
142 return v0.quat_ == v1.quat_ || v0.quat_ == -v1.quat_;
145 return v0.quat_ != v1.quat_ && v0.quat_ != -v1.quat_;
155 Rotation(
T q0,
T q1,
T q2,
T q3) : quat_(q0, q1, q2, q3) {}
162 return v + quat_[3] * temp +
Cross(im, temp);
172 template <
typename T>
174 const typename Rotation<T>::VectorType& v)
const {
175 return ApplyToVector(v);
178 template <
typename T>
184 template <
typename T>
185 std::ostream& operator<<(std::ostream& out, const Rotation<T>& a) {
188 a.GetAxisAndAngle(&axis, &angle);
189 return out <<
"ROT[" << axis <<
": " << angle <<
"]";
193 template <
typename T>
198 if (in >> axis >> base::GetExpectedChar<':'> >> angle
218 #endif // ION_MATH_ROTATION_H_
static Rotation Slerp(const Rotation &r0, const Rotation &r1, T t)
Performs spherical linear interpolation between two Rotation instances.
friend const Rotation operator*(const Rotation &r0, const Rotation &r1)
Binary multiplication operator - returns a composite Rotation.
friend bool operator==(const Rotation &v0, const Rotation &v1)
Exact equality and inequality comparisons.
Rotation< double > Rotationd
void GetEulerAngles(AngleType *yaw, AngleType *pitch, AngleType *roll) const
Returns the Euler angles which would result in this rotation if done in the order of rotate-Y by yaw...
bool IsIdentity() const
Returns true if this represents an identity Rotation.
A simple class to represent angles.
Vector< 4, T > QuaternionType
static Rotation FromQuaternion(const QuaternionType &quat)
Convienance function that constructs and returns a Rotation given a quaternion.
void Set(T e0)
Sets the vector values.
The Matrix class defines a square N-dimensional matrix.
friend Rotation operator-(const Rotation &r)
The negation operator returns the inverse rotation.
const QuaternionType & GetQuaternion() const
Returns the Rotation as a normalized quaternion (4D vector).
static Rotation Identity()
Returns an identity Rotation, which has no effect.
void SetQuaternion(const QuaternionType &quaternion)
Sets the Rotation from a quaternion (4D vector), which is first normalized.
const Vector< Dimension, T > Normalized(const Vector< Dimension, T > &v)
Returns a unit-length version of a Vector.
static Rotation FromRotationMatrix(const Matrix< 3, T > &mat)
Convienance function that constructs and returns a Rotation given a rotation matrix R with $R^ R = I ...
std::istream & GetExpectedChar(std::istream &in)
Reads a single character from the stream and returns the stream.
Vector< 3, T > VectorType
friend bool operator!=(const Rotation &v0, const Rotation &v1)
The Rotation class represents a rotation around a 3-dimensional axis.
std::istream & GetExpectedString(std::istream &in, const std::string &expected)
Attempts to read a string from the stream and returns the stream.
void GetAxisAndAngle(VectorType *axis, AngleType *angle) const
Returns the right-hand rule axis and angle corresponding to the Rotation.
static Rotation RotateInto(const VectorType &from, const VectorType &to)
Constructs and returns a Rotation that rotates one vector to another along the shortest arc...
static const Point Zero()
Returns a Point containing all zeroes.
Rotation & operator*=(const Rotation &r)
Appends a rotation to this one.
Rotation()
The default constructor creates an identity Rotation, which has no effect.
std::istream & operator>>(std::istream &in, Angle< T > &a)
Rotation< float > Rotationf
Type-specific typedefs.
void SetAxisAndAngle(const VectorType &axis, const AngleType &angle)
Sets the Rotation to rotate by the given angle around the given axis, following the right-hand rule...
Angle< T > AngleType
Convenience typedefs for Angle and 3D vector of the correct type.
Vector< 3, T > Cross(const Vector< 3, T > &v0, const Vector< 3, T > &v1)
Returns the 3-dimensional cross product of 2 Vectors.
static Rotation FromAxisAndAngle(const VectorType &axis, const AngleType &angle)
Convenience function that constructs and returns a Rotation given an axis and angle.