# LQuaternionf

class LQuaternionf

Bases: `LVecBase4f`

This is the base quaternion class

Inheritance diagram

LQuaternionf(void)
LQuaternionf(LVecBase4f const &copy)
LQuaternionf(float r, LVecBase3f const &copy)
LQuaternionf(float r, float i, float j, float k)
LQuaternionf(LQuaternionf const&) = default
bool almost_equal(LQuaternionf const &other) const
bool almost_equal(LQuaternionf const &other, float threshold) const

Returns true if two quaternions are memberwise equal within a default tolerance based on the numeric type.

Returns true if two quaternions are memberwise equal within a specified tolerance.

bool almost_same_direction(LQuaternionf const &other, float threshold) const

Returns true if two quaternions represent the same rotation within a specified tolerance.

float angle_deg(LQuaternionf const &other) const

Returns the angle between the orientation represented by this quaternion and the other one, expressed in degrees.

Returns the angle between the orientation represented by this quaternion and the other one, expressed in radians.

LQuaternionf conjugate(void) const

Returns the complex conjugate of this quat.

bool conjugate_from(LQuaternionf const &other)

Computes the conjugate of the other quat, and stores the result in this quat. This is a fully general operation and makes no assumptions about the type of transform represented by the quat.

The other quat must be a different object than this quat. However, if you need to get a conjugate of a quat in place, see `conjugate_in_place`.

The return value is true if the quat was successfully inverted, false if there was a singularity.

bool conjugate_in_place(void)

Sets this to be the conjugate of the current quat. Returns true if the successful, false if the quat was singular.

void extract_to_matrix(LMatrix3f &m) const
void extract_to_matrix(LMatrix4f &m) const

Based on the quat lib from VRPN.

float get_angle(void) const

This, along with `get_axis()`, returns the rotation represented by the quaternion as an angle about an arbitrary axis. This returns the angle, in degrees counterclockwise about the axis.

It is necessary to ensure the quaternion has been normalized (for instance, with a call to `normalize()`) before calling this method.

This, along with `get_axis()`, returns the rotation represented by the quaternion as an angle about an arbitrary axis. This returns the angle, in radians counterclockwise about the axis.

It is necessary to ensure the quaternion has been normalized (for instance, with a call to `normalize()`) before calling this method.

LVector3f get_axis(void) const

This, along with `get_angle()`, returns the rotation represented by the quaternion as an angle about an arbitrary axis. This returns the axis; it is not normalized.

LVector3f get_axis_normalized(void) const

This, along with `get_angle()`, returns the rotation represented by the quaternion as an angle about an arbitrary axis. This returns the normalized axis.

static TypeHandle get_class_type(void)
LVector3f get_forward(CoordinateSystem cs = ::CS_default) const

Returns the orientation represented by this quaternion, expressed as a forward vector.

LVecBase3f get_hpr(CoordinateSystem cs = ::CS_default) const

Extracts the equivalent Euler angles from the unit quaternion.

float get_i(void) const
float get_j(void) const
float get_k(void) const
float get_r(void) const
LVector3f get_right(CoordinateSystem cs = ::CS_default) const

Returns the orientation represented by this quaternion, expressed as a right vector.

LVector3f get_up(CoordinateSystem cs = ::CS_default) const

Returns the orientation represented by this quaternion, expressed as an up vector.

LQuaternionf const &ident_quat(void)

Returns an identity quaternion.

bool invert_from(LQuaternionf const &other)

Computes the inverse of the other quat, and stores the result in this quat. This is a fully general operation and makes no assumptions about the type of transform represented by the quat.

The other quat must be a different object than this quat. However, if you need to invert a quat in place, see `invert_in_place`.

The return value is true if the quat was successfully inverted, false if there was a singularity.

bool invert_in_place(void)

Inverts the current quat. Returns true if the inverse is successful, false if the quat was singular.

bool is_almost_identity(float tolerance) const

Returns true if this quaternion represents the identity transformation within a given tolerance.

bool is_identity(void) const

Returns true if this quaternion represents the identity transformation: no rotation.

bool is_same_direction(LQuaternionf const &other) const

Returns true if two quaternions represent the same rotation within a default tolerance based on the numeric type.

LQuaternionf multiply(LQuaternionf const &rhs) const

actual multiply call (non virtual)

bool normalize(void)
void output(std::ostream&) const
static LQuaternionf pure_imaginary(LVector3f const &v)
void set_from_axis_angle(float angle_deg, LVector3f const &axis)

`angle_deg` is the angle about the axis in degrees. axis must be normalized.

`angle_rad` is the angle about the axis in radians. axis must be normalized.

void set_from_matrix(LMatrix3f const &m)
void set_from_matrix(LMatrix4f const &m)

Sets the quaternion according to the rotation represented by the matrix. Originally we tried an algorithm presented by Do-While Jones, but that turned out to be broken. This is based on the quat lib from UNC.

void set_hpr(LVecBase3f const &hpr, CoordinateSystem cs = ::CS_default)

Sets the quaternion as the unit quaternion that is equivalent to these Euler angles. (from Real-time Rendering, p.49)

void set_i(float i)
void set_j(float j)
void set_k(float k)
void set_r(float r)
LVecBase3f xform(LVecBase3f const &v) const
LVecBase4f xform(LVecBase4f const &v) const

Transforms a 3-d vector by the indicated rotation

Transforms a 4-d vector by the indicated rotation