Quat

The Quat class template represents a quaterion rotation/orientation, with predefined typedefs for float and double.

Example:

#include <Imath/ImathQuat.h>
#include <cassert>

void
quat_example()
{
    Imath::Quatf q (2.0f, 3.0f, 4.0f, 5.0f);
    assert (q.r == 2.0f && q.v == Imath::V3f (3.0f, 4.0f, 5.0f));

    Imath::Quatf r (1.0f, 0.0f, 0.0f, 1.0f);
    assert (r.inverse() == Imath::Quatf (0.5f, 0.0f, 0.0f, -0.5f));
}
typedef Quat<float> Imath::Quatf

Quaternion of type float.

template<class T>
class Quat

The Quat class implements the quaternion numerical type you will probably want to use this class to represent orientations in R3 and to convert between various euler angle reps.

You should probably use Imath::Euler<> for that.

Direct access to elements

T r

The real part.

Vec3<T> v

The imaginary vector.

Constructors

constexpr Quat()

Default constructor is the identity quat.

constexpr Quat(const Quat &q)

Copy constructor.

template<class S>
constexpr Quat(const Quat<S> &q)

Construct from a quaternion of a another base type.

constexpr Quat(T s, T i, T j, T k)

Initialize with real part s and imaginary vector 1(i,j,k)`.

constexpr Quat(T s, Vec3<T> d)

Initialize with real part s and imaginary vector d

constexpr const Quat<T> &operator=(const Quat<T> &q)

Assignment.

~Quat()

Destructor.

constexpr Quat<T> identity()

The identity quaternion.

Basic Algebra

Note that the operator return values are NOT normalized

constexpr const Quat<T> &operator*=(const Quat<T> &q)

Quaternion multiplication.

constexpr const Quat<T> &operator*=(T t)

Scalar multiplication: multiply both real and imaginary parts by the given scalar.

constexpr const Quat<T> &operator/=(const Quat<T> &q)

Quaterion division, using the inverse()

constexpr const Quat<T> &operator/=(T t)

Scalar division: multiply both real and imaginary parts by the given scalar.

constexpr const Quat<T> &operator+=(const Quat<T> &q)

Quaternion addition.

constexpr const Quat<T> &operator-=(const Quat<T> &q)

Quaternion subtraction.

template<class S>
constexpr bool operator==(const Quat<S> &q) const

Equality.

template<class S>
constexpr bool operator!=(const Quat<S> &q) const

Inequality.

Query

constexpr T length() const

Return the R4 length.

constexpr T angle() const

Return the angle of the axis/angle representation.

constexpr Vec3<T> axis() const

Return the axis of the axis/angle representation.

constexpr Matrix33<T> toMatrix33() const

Return a 3x3 rotation matrix.

constexpr Matrix44<T> toMatrix44() const

Return a 4x4 rotation matrix.

Quat<T> log() const

Return the logarithm of the quaterion.

Quat<T> exp() const

Return the exponent of the quaterion.

Utility Methods

constexpr Quat<T> &invert()

Invert in place: this = 1 / this.

Return
const reference to this.

constexpr Quat<T> inverse() const

Return 1/this, leaving this unchanged.

constexpr Quat<T> &normalize()

Normalize in place.

Return
const reference to this.

constexpr Quat<T> normalized() const

Return a normalized quaternion, leaving this unmodified.

constexpr Vec3<T> rotateVector(const Vec3<T> &original) const

Rotate the given point by the quaterion.

constexpr T euclideanInnerProduct(const Quat<T> &q) const

Return the Euclidean inner product.

constexpr Quat<T> &setAxisAngle(const Vec3<T> &axis, T radians)

Set the quaterion to be a rotation around the given axis by the given angle.

Return
const reference to this.

constexpr Quat<T> &setRotation(const Vec3<T> &fromDirection, const Vec3<T> &toDirection)

Set the quaternion to be a rotation that transforms the direction vector fromDirection to toDirection

Return
const reference to this.

Public Types

typedef T BaseType

The base type: In templates that accept a parameter V, you can refer to T as V::BaseType

Public Functions

constexpr T &operator[](int index)

Element access: q[0] is the real part, (q[1],q[2],q[3]) is the imaginary part.

constexpr T operator[](int index) const

Element access: q[0] is the real part, (q[1],q[2],q[3]) is the imaginary part.

Warning

doxygenfunction: Unable to resolve multiple matches for function “operator<<” with arguments (std::ostream& s, const Quat<T>& q) in doxygen xml output for project “Imath” from directory: /build/ilmbase-5Yemou/ilmbase-3.1.11/obj-x86_64-linux-gnu/website/doxygen/xml. Potential matches:

- std::ostream &operator<<(std::ostream&, Imath::half)
- template<class T>
  std::ostream &Imath::operator<<(std::ostream&, const Color4<T>&)
- template<class T>
  std::ostream &Imath::operator<<(std::ostream&, const Euler<T>&)
- template<class T>
  std::ostream &Imath::operator<<(std::ostream&, const Interval<T>&)
- template<class T>
  std::ostream &Imath::operator<<(std::ostream&, const Line3<T>&)
- template<class T>
  std::ostream &Imath::operator<<(std::ostream&, const Matrix22<T>&)
- template<class T>
  std::ostream &Imath::operator<<(std::ostream&, const Matrix33<T>&)
- template<class T>
  std::ostream &Imath::operator<<(std::ostream&, const Matrix44<T>&)
- template<class T>
  std::ostream &Imath::operator<<(std::ostream&, const Plane3<T>&)
- template<class T>
  std::ostream &Imath::operator<<(std::ostream&, const Quat<T>&)
- template<class T>
  std::ostream &Imath::operator<<(std::ostream&, const Shear6<T>&)
- template<class T>
  std::ostream &Imath::operator<<(std::ostream&, const Vec2<T>&)
- template<class T>
  std::ostream &Imath::operator<<(std::ostream&, const Vec3<T>&)
- template<class T>
  std::ostream &Imath::operator<<(std::ostream&, const Vec4<T>&)