Quaternion
Object Hierarchy:
Description:
[ Compact ]
public class Quaternion
A quaternion is comprised of a scalar component and a 3D vector component.
The scalar component is normally referred to as w and the vector might either be referred to as v or a (for axis) or expanded with the
individual components: (x, y, z) A full quaternion would then be written as <literal>[w (x, y, z)]</literal>.
Quaternions can be considered to represent an axis and angle pair although sadly these numbers are buried somewhat under some maths...
For the curious you can see here that a given axis (a) and angle (𝜃) pair are represented in a quaternion as follows:
[w=cos(𝜃/2) ( x=sin(𝜃/2)*a.x, y=sin(𝜃/2)*a.y, z=sin(𝜃/2)*a.x )]
rnions: When using Quaternions to represent spatial orientations for 3D graphics it's always assumed you have a unit quaternion. The
magnitude of a quaternion is defined as:
sqrt (w² + x² + y² + z²)
a unit quaternion satisfies this
equation:
w² + x² + y² + z² = 1
ankfully most of the time we don't actually have to worry about the
maths that goes on behind the scenes but if you are curious to learn more here are some external references:
<itemizedlist> <listitem> <ulink url="http://mathworld.wolfram.com/Quaternion.html"/> </listitem> <listitem
> <ulink url="http://www.gamedev.net/reference/articles/article1095.asp"/> </listitem> <listitem> <ulink
url="http://www.cprogramming.com/tutorial/3d/quaternions.html"/> </listitem> <listitem> <ulink
url="http://www.isner.com/tutorials/quatSpells/quaternion_spells_12.htm"/> </listitem> <listitem> 3D Maths Primer for
Graphics and Game Development ISBN-10: 1556229119 </listitem> <listitem> <ulink
url="http://www.cs.caltech.edu/courses/cs171/quatut.pdf"/> </listitem> <listitem> <ulink
url="http://www.j3d.org/matrix_faq/matrfaq_latest.html#Q56"/> </listitem> </itemizedlist>
Content:
Static methods:
Methods:
- public Quaternion copy ()
Allocates a new Quaternion on the stack and
initializes it with the same values as this.
- public float dot_product (Quaternion b)
- public void free ()
Frees a Quaternion that was previously
allocated via copy.
- public float get_rotation_angle ()
- public void get_rotation_axis (out float vector3)
- public void init (float angle, float x, float y, float z)
Initializes a quaternion that rotates angle
degrees
around the axis vector (x
, y
, z
).
- public void init_from_angle_vector (float angle, float axis3f)
Initializes a quaternion that rotates angle
degrees
around the given axis
vector.
- public void init_from_array (float array)
Initializes a [w (x, y,z)] quaternion directly from an array of 4
floats: [w,x,y,z].
- public void init_from_euler (Euler euler)
- public void init_from_matrix (Matrix matrix)
Initializes a quaternion from a rotation matrix.
- public void init_from_quaternion (Quaternion src)
- public void init_from_x_rotation (float angle)
XXX: check which direction this rotates
- public void init_from_y_rotation (float angle)
- public void init_from_z_rotation (float angle)
- public void init_identity ()
Initializes the quaternion with the canonical quaternion identity [1 (
0, 0, 0)] which represents no rotation.
- public void invert ()
- public void multiply (Quaternion left, Quaternion right)
This combines the rotations of two quaternions into
this.
- public void nlerp (Quaternion a, Quaternion b, float t)
Performs a normalized linear interpolation between two quaternions.
- public void normalize ()
- public void pow (float exponent)
- public void slerp (Quaternion a, Quaternion b, float t)
Performs a spherical linear interpolation between two quaternions.
- public void squad (Quaternion prev, Quaternion a, Quaternion b, Quaternion next, float t)
Fields:
- public float w
- public float x
- public float y
- public float z