LQuaterniond Class Reference

This is the base quaternion class. More...

Inheritance diagram for LQuaterniond: ## Public Member Functions

__init__ ()

__init__ (const LQuaterniond)

__init__ (const LVecBase4d copy)

__init__ (double r, const LVecBase3d copy)

__init__ (double r, double i, double j, double k)

LQuaterniond __pow__ (double)
Returns a new quaternion that represents this quaternion raised to the given power. More...

bool almostEqual (const LQuaterniond other)
Returns true if two quaternions are memberwise equal within a default tolerance based on the numeric type. More...

bool almostEqual (const LQuaterniond other, double threshold)
Returns true if two quaternions are memberwise equal within a specified tolerance. More...

bool almostSameDirection (const LQuaterniond other, double threshold)
Returns true if two quaternions represent the same rotation within a specified tolerance. More...

double angleDeg (const LQuaterniond other)
Returns the angle between the orientation represented by this quaternion and the other one, expressed in degrees. More...

double angleRad (const LQuaterniond other)
Returns the angle between the orientation represented by this quaternion and the other one, expressed in radians. More...

LQuaterniond conjugate ()
Returns the complex conjugate of this quat. More...

bool conjugateFrom (const LQuaterniond other)
Computes the conjugate of the other quat, and stores the result in this quat. More...

bool conjugateInPlace ()
Sets this to be the conjugate of the current quat. More...

extractToMatrix (LMatrix3d m)
Based on the quat lib from VRPN. More...

extractToMatrix (LMatrix4d m)
Based on the quat lib from VRPN. More...

double getAngle ()
This, along with get_axis(), returns the rotation represented by the quaternion as an angle about an arbitrary axis. More...

double getAngleRad ()
This, along with get_axis(), returns the rotation represented by the quaternion as an angle about an arbitrary axis. More...

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

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

LVector3d getForward (CoordinateSystem cs)
Returns the orientation represented by this quaternion, expressed as a forward vector. More...

LVecBase3d getHpr (CoordinateSystem cs)
Extracts the equivalent Euler angles from the unit quaternion. More...

double getI ()

double getJ ()

double getK ()

double getR ()

LVector3d getRight (CoordinateSystem cs)
Returns the orientation represented by this quaternion, expressed as a right vector. More...

LVector3d getUp (CoordinateSystem cs)
Returns the orientation represented by this quaternion, expressed as an up vector. More...

bool invertFrom (const LQuaterniond other)
Computes the inverse of the other quat, and stores the result in this quat. More...

bool invertInPlace ()
Inverts the current quat. More...

bool isAlmostIdentity (double tolerance)
Returns true if this quaternion represents the identity transformation within a given tolerance. More...

bool isIdentity ()
Returns true if this quaternion represents the identity transformation: no rotation. More...

bool isSameDirection (const LQuaterniond other)
Returns true if two quaternions represent the same rotation within a default tolerance based on the numeric type. More...

LQuaterniond multiply (const LQuaterniond rhs)
actual multiply call (non virtual) More...

bool normalize ()

LMatrix3d operator * (const LMatrix3d)

LMatrix4d operator * (const LMatrix4d)

LQuaterniond operator * (const LQuaterniond)

LQuaterniond operator * (double scalar)

LQuaterniond operator *= (const LQuaterniond)

LQuaterniond operator - ()

LQuaterniond operator - (const LQuaterniond other)

LQuaterniond operator+ (const LQuaterniond other)

LQuaterniond operator/ (double scalar)

output (Ostream)

setFromAxisAngle (double angle_deg, const LVector3d axis)
angle_deg is the angle about the axis in degrees. More...

setFromAxisAngleRad (double angle_rad, const LVector3d axis)
angle_rad is the angle about the axis in radians. More...

setFromMatrix (const LMatrix3d m)
Sets the quaternion according to the rotation represented by the matrix. More...

setFromMatrix (const LMatrix4d m)

setHpr (const LVecBase3d hpr, CoordinateSystem cs)
Sets the quaternion as the unit quaternion that is equivalent to these Euler angles. More...

setI (double i)

setJ (double j)

setK (double k)

setR (double r)

LVecBase3d xform (const LVecBase3d v)
Transforms a 3-d vector by the indicated rotation. More...

LVecBase4d xform (const LVecBase4d v)
Transforms a 4-d vector by the indicated rotation. More... Public Member Functions inherited from LVecBase4d
object __getattr__ (str attr_name)

__init__ ()

__init__ (const LPoint3d point)
Constructs an LVecBase4 from an LPoint3. More...

__init__ (const LVecBase3d copy, double w)

__init__ (const LVecBase4d)

__init__ (const LVector3d vector)
Constructs an LVecBase4 from an LVector3. More...

__init__ (const UnalignedLVecBase4d copy)

__init__ (double fill_value)

__init__ (double x, double y, double z, double w)

object __ipow__ (double exponent)

LVecBase4d __pow__ (double exponent)

object __reduce__ ()

str __repr__ ()

int __setattr__ (str attr_name, object assign)

int addHash (int hash)
Adds the vector into the running hash. More...

int addHash (int hash, double threshold)
Adds the vector into the running hash. More...

addToCell (int i, double value)

addW (double value)

addX (double value)

addY (double value)

addZ (double value)

bool almostEqual (const LVecBase4d other)
Returns true if two vectors are memberwise equal within a default tolerance based on the numeric type. More...

bool almostEqual (const LVecBase4d other, double threshold)
Returns true if two vectors are memberwise equal within a specified tolerance. More...

int compareTo (const LVecBase4d other)
This flavor of compare_to uses a default threshold value based on the numeric type. More...

int compareTo (const LVecBase4d other, double threshold)
Sorts vectors lexicographically, componentwise. More...

componentwiseMult (const LVecBase4d other)

double dot (const LVecBase4d other)

fill (double fill_value)
Sets each element of the vector to the indicated fill_value. More...

LVecBase4d fmax (const LVecBase4d other)

LVecBase4d fmin (const LVecBase4d other)

generateHash (ChecksumHashGenerator hashgen)
Adds the vector to the indicated hash generator. More...

generateHash (ChecksumHashGenerator hashgen, double threshold)
Adds the vector to the indicated hash generator. More...

double getCell (int i)

getData ()
Returns the address of the first of the four data elements in the vector. More...

int getHash ()
Returns a suitable hash for phash_map. More...

int getHash (double threshold)
Returns a suitable hash for phash_map. More...

double getW ()

double getX ()

LVecBase2d getXy ()
Returns the x and y component of this vector. More...

LVecBase3d getXyz ()
Returns the x, y and z component of this vector. More...

double getY ()

double getZ ()

bool isNan ()
Returns true if any component of the vector is not-a-number, false otherwise. More...

double length ()
Returns the length of the vector, by the Pythagorean theorem. More...

double lengthSquared ()
Returns the square of the vector's length, cheap and easy. More...

bool normalize ()
Normalizes the vector in place. More...

LVecBase4d normalized ()
Normalizes the vector and returns the normalized vector as a copy. More...

bool operator != (const LVecBase4d other)

LVecBase4d operator * (double scalar)

LVecBase4d operator *= (double scalar)

LVecBase4d operator - ()

LVecBase4d operator - (const LVecBase4d other)

LVecBase4d operator -= (const LVecBase4d other)

operator [] (int i, double assign_val)

double operator [] (int i)

operator new (int size)

LVecBase4d operator+ (const LVecBase4d other)

LVecBase4d operator+= (const LVecBase4d other)

LVecBase4d operator/ (double scalar)

LVecBase4d operator/= (double scalar)

bool operator< (const LVecBase4d other)

LVecBase4d operator= (const LVecBase4d copy)

LVecBase4d operator= (double fill_value)

bool operator== (const LVecBase4d other)

output (Ostream out)

LVecBase4d project (const LVecBase4d onto)
Returns a new vector representing the projection of this vector onto another one. More...

readDatagram (DatagramIterator source)
Reads the vector from the Datagram using get_stdfloat(). More...

readDatagramFixed (DatagramIterator source)
Reads the vector from the Datagram using get_float32() or get_float64(). More...

set (double x, double y, double z, double w)

setCell (int i, double value)

setW (double value)

setX (double value)

setY (double value)

setZ (double value)

writeDatagram (Datagram destination)
Writes the vector to the Datagram using add_stdfloat(). More...

writeDatagramFixed (Datagram destination)
Writes the vector to the Datagram using add_float32() or add_float64(), depending on the type of floats in the vector, regardless of the setting of Datagram::set_stdfloat_double(). More...

## Static Public Member Functions

static TypeHandle getClassType ()

static const LQuaterniond identQuat ()
Returns an identity quaternion. More...

static LQuaterniond pureImaginary (const LVector3d v) Static Public Member Functions inherited from LVecBase4d
static TypeHandle getClassType ()

static int getNumComponents ()

static int size ()

static const LVecBase4d unitW ()
Returns a unit W vector. More...

static const LVecBase4d unitX ()
Returns a unit X vector. More...

static const LVecBase4d unitY ()
Returns a unit Y vector. More...

static const LVecBase4d unitZ ()
Returns a unit Z vector. More...

static const LVecBase4d zero ()
Returns a zero-length vector. More...

## Additional Inherited Members Public Types inherited from LVecBase4d
enum  { num_components = 4, is_int = 0 } Public Attributes inherited from LVecBase4d
double x

LVecBase2d xy
Returns the x and y component of this vector. More...

LVecBase3d xyz
Returns the x, y and z component of this vector. More...

double y

double z

## Detailed Description

This is the base quaternion class.

## ◆ __init__() [1/5]

 __init__ ( )

## ◆ __init__() [2/5]

 __init__ ( const LQuaterniond )

## ◆ __init__() [3/5]

 __init__ ( const LVecBase4d copy )

## ◆ __init__() [4/5]

 __init__ ( double r, const LVecBase3d copy )

## ◆ __init__() [5/5]

 __init__ ( double r, double i, double j, double k )

## ◆ __pow__()

 LQuaterniond __pow__ ( double )

Returns a new quaternion that represents this quaternion raised to the given power.

## ◆ almostEqual() [1/2]

 bool almostEqual ( const LQuaterniond other )

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

## ◆ almostEqual() [2/2]

 bool almostEqual ( const LQuaterniond other, double threshold )

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

## ◆ almostSameDirection()

 bool almostSameDirection ( const LQuaterniond other, double threshold )

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

## ◆ angleDeg()

 double angleDeg ( const LQuaterniond other )

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

## ◆ angleRad()

 double angleRad ( const LQuaterniond other )

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

## ◆ conjugate()

 LQuaterniond conjugate ( )

Returns the complex conjugate of this quat.

## ◆ conjugateFrom()

 bool conjugateFrom ( const LQuaterniond 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.

## ◆ conjugateInPlace()

 bool conjugateInPlace ( )

Sets this to be the conjugate of the current quat.

Returns true if the successful, false if the quat was singular.

## ◆ extractToMatrix() [1/2]

 extractToMatrix ( LMatrix3d m )

Based on the quat lib from VRPN.

## ◆ extractToMatrix() [2/2]

 extractToMatrix ( LMatrix4d m )

Based on the quat lib from VRPN.

## ◆ getAngle()

 double getAngle ( )

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.

## ◆ getAngleRad()

 double getAngleRad ( )

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.

## ◆ getAxis()

 LVector3d getAxis ( )

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.

## ◆ getAxisNormalized()

 LVector3d getAxisNormalized ( )

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

This returns the normalized axis.

## ◆ getClassType()

 static TypeHandle getClassType ( )
static

## ◆ getForward()

 LVector3d getForward ( CoordinateSystem cs )

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

## ◆ getHpr()

 LVecBase3d getHpr ( CoordinateSystem cs )

Extracts the equivalent Euler angles from the unit quaternion.

## ◆ getI()

 double getI ( )

## ◆ getJ()

 double getJ ( )

## ◆ getK()

 double getK ( )

## ◆ getR()

 double getR ( )

## ◆ getRight()

 LVector3d getRight ( CoordinateSystem cs )

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

## ◆ getUp()

 LVector3d getUp ( CoordinateSystem cs )

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

## ◆ identQuat()

 static const LQuaterniond identQuat ( )
static

Returns an identity quaternion.

## ◆ invertFrom()

 bool invertFrom ( const LQuaterniond 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.

## ◆ invertInPlace()

 bool invertInPlace ( )

Inverts the current quat.

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

## ◆ isAlmostIdentity()

 bool isAlmostIdentity ( double tolerance )

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

## ◆ isIdentity()

 bool isIdentity ( )

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

## ◆ isSameDirection()

 bool isSameDirection ( const LQuaterniond other )

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

## ◆ multiply()

 LQuaterniond multiply ( const LQuaterniond rhs )

actual multiply call (non virtual)

## ◆ normalize()

 bool normalize ( )

## ◆ operator *() [1/4]

 LMatrix3d operator * ( const LMatrix3d )

## ◆ operator *() [2/4]

 LMatrix4d operator * ( const LMatrix4d )

## ◆ operator *() [3/4]

 LQuaterniond operator * ( const LQuaterniond )

## ◆ operator *() [4/4]

 LQuaterniond operator * ( double scalar )

## ◆ operator *=()

 LQuaterniond operator *= ( const LQuaterniond )

## ◆ operator -() [1/2]

 LQuaterniond operator - ( )

## ◆ operator -() [2/2]

 LQuaterniond operator - ( const LQuaterniond other )

## ◆ operator+()

 LQuaterniond operator+ ( const LQuaterniond other )

## ◆ operator/()

 LQuaterniond operator/ ( double scalar )

## ◆ output()

 output ( Ostream )

## ◆ pureImaginary()

 static LQuaterniond pureImaginary ( const LVector3d v )
static

## ◆ setFromAxisAngle()

 setFromAxisAngle ( double angle_deg, const LVector3d axis )

angle_deg is the angle about the axis in degrees.

axis must be normalized.

## ◆ setFromAxisAngleRad()

 setFromAxisAngleRad ( double angle_rad, const LVector3d axis )

angle_rad is the angle about the axis in radians.

axis must be normalized.

## ◆ setFromMatrix() [1/2]

 setFromMatrix ( const LMatrix3d 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.

## ◆ setFromMatrix() [2/2]

 setFromMatrix ( const LMatrix4d m )

## ◆ setHpr()

 setHpr ( const LVecBase3d hpr, CoordinateSystem cs )

Sets the quaternion as the unit quaternion that is equivalent to these Euler angles.

(from Real-time Rendering, p.49)

## ◆ setI()

 setI ( double i )

## ◆ setJ()

 setJ ( double j )

## ◆ setK()

 setK ( double k )

## ◆ setR()

 setR ( double r )

## ◆ xform() [1/2]

 LVecBase3d xform ( const LVecBase3d v )

Transforms a 3-d vector by the indicated rotation.

## ◆ xform() [2/2]

 LVecBase4d xform ( const LVecBase4d v )

Transforms a 4-d vector by the indicated rotation.