APIdia Launch Partner
Top Description Fields Constructors Methods
com.badlogic.gdx.math

public Class Quaternion

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.io.Serializable, com.badlogic.gdx.utils.NumberUtils

A simple quaternion class.
Authors
[email protected], vesuvio, xoppa
See Also
http://en.wikipedia.org/wiki/Quaternion

Field Summary

Modifier and TypeField and Description
private static final long
private static Quaternion
private static Quaternion
public float
w

public float
x

public float
y

public float
z

Constructor Summary

AccessConstructor and Description
public
Quaternion(float
The x-component
x
,
float
The y-component
y
,
float
The z-component
z
,
float
The w-component
w
)

Constructor, sets the four components of the quaternion.

public
public
Quaternion(Quaternion
The quaternion to copy.
quaternion
)

Constructor, sets the quaternion components from the given quaternion.

public
Quaternion(Vector3
The axis
axis
,
float
The angle in degrees.
angle
)

Constructor, sets the quaternion from the given axis vector and the angle around that axis in degrees.

Method Summary

Modifier and TypeMethod and Description
public Quaternion
add(Quaternion quaternion)

Add the x,y,z,w components of the passed in quaternion to the ones of this quaternion

public Quaternion
add(float qx, float qy, float qz, float qw)

Add the x,y,z,w components of the passed in quaternion to the ones of this quaternion

public Quaternion

Returns:

This quaternion for chaining
conjugate
()

Conjugate the quaternion.

public Quaternion
cpy()

Returns: a copy of this quaternion

public static final float

Returns:

the dot product between the first and second quaternion.
dot
(final float
the x component of the first quaternion
x1
,
final float
the y component of the first quaternion
y1
,
final float
the z component of the first quaternion
z1
,
final float
the w component of the first quaternion
w1
,
final float
the x component of the second quaternion
x2
,
final float
the y component of the second quaternion
y2
,
final float
the z component of the second quaternion
z2
,
final float
the w component of the second quaternion
w2
)

Get the dot product between the two quaternions (commutative).

public float

Returns:

the dot product of this and the other quaternion.
dot
(final Quaternion
the other quaternion.
other
)

Get the dot product between this and the other quaternion (commutative).

public float

Returns:

the dot product of this and the other quaternion.
dot
(final float
the x component of the other quaternion
x
,
final float
the y component of the other quaternion
y
,
final float
the z component of the other quaternion
z
,
final float
the w component of the other quaternion
w
)

Get the dot product between this and the other quaternion (commutative).

public boolean
equals(Object obj)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public Quaternion

Returns:

This quaternion for chaining
exp
(float
Exponent
alpha
)

Calculates (this quaternion)^alpha where alpha is a real number and stores the result in this quaternion.

public float

Returns:

the angle in degrees of the rotation
getAngle
()

Get the angle in degrees of the rotation this quaternion represents.

public float

Returns:

the angle in degrees of the rotation around the specified axis
getAngleAround
(final float
the x component of the normalized axis for which to get the angle
axisX
,
final float
the y component of the normalized axis for which to get the angle
axisY
,
final float
the z component of the normalized axis for which to get the angle
axisZ
)

Get the angle in degrees of the rotation around the specified axis.

public float

Returns:

the angle in degrees of the rotation around the specified axis
getAngleAround
(final Vector3
the normalized axis for which to get the angle
axis
)

Get the angle in degrees of the rotation around the specified axis.

public float

Returns:

the angle in radians of the rotation around the specified axis
getAngleAroundRad
(final float
the x component of the normalized axis for which to get the angle
axisX
,
final float
the y component of the normalized axis for which to get the angle
axisY
,
final float
the z component of the normalized axis for which to get the angle
axisZ
)

Get the angle in radians of the rotation around the specified axis.

public float

Returns:

the angle in radians of the rotation around the specified axis
getAngleAroundRad
(final Vector3
the normalized axis for which to get the angle
axis
)

Get the angle in radians of the rotation around the specified axis.

public float

Returns:

the angle in radians of the rotation
getAngleRad
()

Get the angle in radians of the rotation this quaternion represents.

public float

Returns:

the angle in degrees
getAxisAngle
(Vector3
vector which will receive the axis
axis
)

Get the axis angle representation of the rotation in degrees.

public float

Returns:

the angle in radians
getAxisAngleRad
(Vector3
vector which will receive the axis
axis
)

Get the axis-angle representation of the rotation in radians.

public int

Returns:

positive (+1) for north pole, negative (-1) for south pole, zero (0) when no gimbal lock
getGimbalPole
()

Get the pole of the gimbal lock, if any.

public float

Returns:

the rotation around the x axis in degrees (between -90 and +90)
getPitch
()

Get the pitch euler angle in degrees, which is the rotation around the x axis.

public float

Returns:

the rotation around the x axis in radians (between -(PI/2) and +(PI/2))
getPitchRad
()

Get the pitch euler angle in radians, which is the rotation around the x axis.

public float

Returns:

the rotation around the z axis in degrees (between -180 and +180)
getRoll
()

Get the roll euler angle in degrees, which is the rotation around the z axis.

public float

Returns:

the rotation around the z axis in radians (between -PI and +PI)
getRollRad
()

Get the roll euler angle in radians, which is the rotation around the z axis.

public void
getSwingTwist(final float
the X component of the normalized axis for which to get the swing and twist rotation
axisX
,
final float
the Y component of the normalized axis for which to get the swing and twist rotation
axisY
,
final float
the Z component of the normalized axis for which to get the swing and twist rotation
axisZ
,
final Quaternion
will receive the swing rotation: the rotation around an axis perpendicular to the specified axis
swing
,
final Quaternion
will receive the twist rotation: the rotation around the specified axis
twist
)

Get the swing rotation and twist rotation for the specified axis.

public void
getSwingTwist(final Vector3
the normalized axis for which to get the swing and twist rotation
axis
,
final Quaternion
will receive the swing rotation: the rotation around an axis perpendicular to the specified axis
swing
,
final Quaternion
will receive the twist rotation: the rotation around the specified axis
twist
)

Get the swing rotation and twist rotation for the specified axis.

public float

Returns:

the rotation around the y axis in degrees (between -180 and +180)
getYaw
()

Get the yaw euler angle in degrees, which is the rotation around the y axis.

public float

Returns:

the rotation around the y axis in radians (between -PI and +PI)
getYawRad
()

Get the yaw euler angle in radians, which is the rotation around the y axis.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public Quaternion

Returns:

this quaternion for chaining
idt
()

Sets the quaternion to an identity Quaternion

public boolean
isIdentity()

Returns: If this quaternion is an identity Quaternion

public boolean
isIdentity(final float tolerance)

Returns: If this quaternion is an identity Quaternion

public static final float
len(final float x, final float y, final float z, final float w)

Returns: the euclidean length of the specified quaternion

public float
len()

Returns: the euclidean length of this quaternion

public static final float
len2(final float x, final float y, final float z, final float w)

public float
len2()

Returns: the length of this quaternion without square root

public Quaternion

Returns:

This quaternion for chaining
mul
(final Quaternion
Quaternion to multiply with
other
)

Multiplies this quaternion with another one in the form of this = this * other

public Quaternion

Returns:

This quaternion for chaining
mul
(final float
the x component of the other quaternion to multiply with
x
,
final float
the y component of the other quaternion to multiply with
y
,
final float
the z component of the other quaternion to multiply with
z
,
final float
the w component of the other quaternion to multiply with
w
)

Multiplies this quaternion with another one in the form of this = this * other

public Quaternion

Returns:

this quaternion for chaining.
mul
(float
the scalar.
scalar
)

Multiplies the components of this quaternion with the given scalar.

public Quaternion

Returns:

This quaternion for chaining
mulLeft
(Quaternion
Quaternion to multiply with
other
)

Multiplies this quaternion with another one in the form of this = other * this

public Quaternion

Returns:

This quaternion for chaining
mulLeft
(final float
the x component of the other quaternion to multiply with
x
,
final float
the y component of the other quaternion to multiply with
y
,
final float
the z component of the other quaternion to multiply with
z
,
final float
the w component of the other quaternion to multiply with
w
)

Multiplies this quaternion with another one in the form of this = other * this

public Quaternion

Returns:

the quaternion for chaining
nor
()

Normalizes this quaternion to unit length

public Quaternion

Returns:

This quaternion for chaining
set
(float
The x-component
x
,
float
The y-component
y
,
float
The z-component
z
,
float
The w-component
w
)

Sets the components of the quaternion

public Quaternion

Returns:

This quaternion for chaining.
set
(Quaternion
The quaternion.
quaternion
)

Sets the quaternion components from the given quaternion.

public Quaternion

Returns:

This quaternion for chaining.
set
(Vector3
The axis
axis
,
float
The angle in degrees
angle
)

Sets the quaternion components from the given axis and angle around that axis.

public Quaternion

Returns:

this quaternion
setEulerAngles
(float
the rotation around the y axis in degrees
yaw
,
float
the rotation around the x axis in degrees
pitch
,
float
the rotation around the z axis degrees
roll
)

Sets the quaternion to the given euler angles in degrees.

public Quaternion

Returns:

this quaternion
setEulerAnglesRad
(float
the rotation around the y axis in radians
yaw
,
float
the rotation around the x axis in radians
pitch
,
float
the rotation around the z axis in radians
roll
)

Sets the quaternion to the given euler angles in radians.

public Quaternion
setFromAxes(float
x-axis x-coordinate
xx
,
float
x-axis y-coordinate
xy
,
float
x-axis z-coordinate
xz
,
float
y-axis x-coordinate
yx
,
float
y-axis y-coordinate
yy
,
float
y-axis z-coordinate
yz
,
float
z-axis x-coordinate
zx
,
float
z-axis y-coordinate
zy
,
float
z-axis z-coordinate
zz
)

Sets the Quaternion from the given x-, y- and z-axis which have to be orthonormal.

public Quaternion
setFromAxes(boolean
whether to normalize the axes (necessary when they contain scaling)
normalizeAxes
,
float
x-axis x-coordinate
xx
,
float
x-axis y-coordinate
xy
,
float
x-axis z-coordinate
xz
,
float
y-axis x-coordinate
yx
,
float
y-axis y-coordinate
yy
,
float
y-axis z-coordinate
yz
,
float
z-axis x-coordinate
zx
,
float
z-axis y-coordinate
zy
,
float
z-axis z-coordinate
zz
)

Sets the Quaternion from the given x-, y- and z-axis.

public Quaternion

Returns:

This quaternion for chaining.
setFromAxis
(final Vector3
The axis
axis
,
final float
The angle in degrees
degrees
)

Sets the quaternion components from the given axis and angle around that axis.

public Quaternion

Returns:

This quaternion for chaining.
setFromAxis
(final float
X direction of the axis
x
,
final float
Y direction of the axis
y
,
final float
Z direction of the axis
z
,
final float
The angle in degrees
degrees
)

Sets the quaternion components from the given axis and angle around that axis.

public Quaternion

Returns:

This quaternion for chaining.
setFromAxisRad
(final Vector3
The axis
axis
,
final float
The angle in radians
radians
)

Sets the quaternion components from the given axis and angle around that axis.

public Quaternion

Returns:

This quaternion for chaining.
setFromAxisRad
(final float
X direction of the axis
x
,
final float
Y direction of the axis
y
,
final float
Z direction of the axis
z
,
final float
The angle in radians
radians
)

Sets the quaternion components from the given axis and angle around that axis.

public Quaternion

Returns:

This quaternion for chaining
setFromCross
(final Vector3
The base vector, which should be normalized.
v1
,
final Vector3
The target vector, which should be normalized.
v2
)

Set this quaternion to the rotation between two vectors.

public Quaternion

Returns:

This quaternion for chaining
setFromCross
(final float
The base vectors x value, which should be normalized.
x1
,
final float
The base vectors y value, which should be normalized.
y1
,
final float
The base vectors z value, which should be normalized.
z1
,
final float
The target vector x value, which should be normalized.
x2
,
final float
The target vector y value, which should be normalized.
y2
,
final float
The target vector z value, which should be normalized.
z2
)

Set this quaternion to the rotation between two vectors.

public Quaternion
setFromMatrix(boolean normalizeAxes, Matrix4 matrix)

Sets the Quaternion from the given matrix, optionally removing any scaling.

public Quaternion
setFromMatrix(Matrix4 matrix)

Sets the Quaternion from the given rotation matrix, which must not contain scaling.

public Quaternion
setFromMatrix(boolean normalizeAxes, Matrix3 matrix)

Sets the Quaternion from the given matrix, optionally removing any scaling.

public Quaternion
setFromMatrix(Matrix3 matrix)

Sets the Quaternion from the given rotation matrix, which must not contain scaling.

public Quaternion

Returns:

this quaternion for chaining
slerp
(Quaternion
the end quaternion
end
,
float
alpha in the range [0,1]
alpha
)

Spherical linear interpolation between this quaternion and the other quaternion, based on the alpha value in the range [0,1].

public Quaternion

Returns:

This quaternion for chaining
slerp
(Quaternion[]
List of quaternions
q
)

Spherical linearly interpolates multiple quaternions and stores the result in this Quaternion.

public Quaternion

Returns:

This quaternion for chaining
slerp
(Quaternion[]
List of quaternions
q
,
float[]
List of weights
w
)

Spherical linearly interpolates multiple quaternions by the given weights and stores the result in this Quaternion.

public void
toMatrix(final float[]
Matrix to fill
matrix
)

Fills a 4x4 matrix with the rotation matrix represented by this quaternion.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public Vector3
transform(Vector3
Vector to transform
v
)

Transforms the given vector using this quaternion

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID
tmp1back to summary
private static Quaternion tmp1
tmp2back to summary
private static Quaternion tmp2
wback to summary
public float w
xback to summary
public float x
yback to summary
public float y
zback to summary
public float z

Constructor Detail

Quaternionback to summary
public Quaternion(float x, float y, float z, float w)

Constructor, sets the four components of the quaternion.

Parameters
x:float

The x-component

y:float

The y-component

z:float

The z-component

w:float

The w-component

Quaternionback to summary
public Quaternion()
Quaternionback to summary
public Quaternion(Quaternion quaternion)

Constructor, sets the quaternion components from the given quaternion.

Parameters
quaternion:Quaternion

The quaternion to copy.

Quaternionback to summary
public Quaternion(Vector3 axis, float angle)

Constructor, sets the quaternion from the given axis vector and the angle around that axis in degrees.

Parameters
axis:Vector3

The axis

angle:float

The angle in degrees.

Method Detail

addback to summary
public Quaternion add(Quaternion quaternion)

Add the x,y,z,w components of the passed in quaternion to the ones of this quaternion

addback to summary
public Quaternion add(float qx, float qy, float qz, float qw)

Add the x,y,z,w components of the passed in quaternion to the ones of this quaternion

conjugateback to summary
public Quaternion conjugate()

Conjugate the quaternion.

Returns:Quaternion

This quaternion for chaining

cpyback to summary
public Quaternion cpy()
Returns:Quaternion

a copy of this quaternion

dotback to summary
public static final float dot(final float x1, final float y1, final float z1, final float w1, final float x2, final float y2, final float z2, final float w2)

Get the dot product between the two quaternions (commutative).

Parameters
x1:float

the x component of the first quaternion

y1:float

the y component of the first quaternion

z1:float

the z component of the first quaternion

w1:float

the w component of the first quaternion

x2:float

the x component of the second quaternion

y2:float

the y component of the second quaternion

z2:float

the z component of the second quaternion

w2:float

the w component of the second quaternion

Returns:float

the dot product between the first and second quaternion.

dotback to summary
public float dot(final Quaternion other)

Get the dot product between this and the other quaternion (commutative).

Parameters
other:Quaternion

the other quaternion.

Returns:float

the dot product of this and the other quaternion.

dotback to summary
public float dot(final float x, final float y, final float z, final float w)

Get the dot product between this and the other quaternion (commutative).

Parameters
x:float

the x component of the other quaternion

y:float

the y component of the other quaternion

z:float

the z component of the other quaternion

w:float

the w component of the other quaternion

Returns:float

the dot product of this and the other quaternion.

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Annotations
@Override
expback to summary
public Quaternion exp(float alpha)

Calculates (this quaternion)^alpha where alpha is a real number and stores the result in this quaternion. See http://en.wikipedia.org/wiki/Quaternion#Exponential.2C_logarithm.2C_and_power

Parameters
alpha:float

Exponent

Returns:Quaternion

This quaternion for chaining

getAngleback to summary
public float getAngle()

Get the angle in degrees of the rotation this quaternion represents. Use getAxisAngle(Vector3) to get both the axis and the angle of this rotation. Use getAngleAround(Vector3) to get the angle around a specific axis.

Returns:float

the angle in degrees of the rotation

getAngleAroundback to summary
public float getAngleAround(final float axisX, final float axisY, final float axisZ)

Get the angle in degrees of the rotation around the specified axis. The axis must be normalized.

Parameters
axisX:float

the x component of the normalized axis for which to get the angle

axisY:float

the y component of the normalized axis for which to get the angle

axisZ:float

the z component of the normalized axis for which to get the angle

Returns:float

the angle in degrees of the rotation around the specified axis

getAngleAroundback to summary
public float getAngleAround(final Vector3 axis)

Get the angle in degrees of the rotation around the specified axis. The axis must be normalized.

Parameters
axis:Vector3

the normalized axis for which to get the angle

Returns:float

the angle in degrees of the rotation around the specified axis

getAngleAroundRadback to summary
public float getAngleAroundRad(final float axisX, final float axisY, final float axisZ)

Get the angle in radians of the rotation around the specified axis. The axis must be normalized.

Parameters
axisX:float

the x component of the normalized axis for which to get the angle

axisY:float

the y component of the normalized axis for which to get the angle

axisZ:float

the z component of the normalized axis for which to get the angle

Returns:float

the angle in radians of the rotation around the specified axis

getAngleAroundRadback to summary
public float getAngleAroundRad(final Vector3 axis)

Get the angle in radians of the rotation around the specified axis. The axis must be normalized.

Parameters
axis:Vector3

the normalized axis for which to get the angle

Returns:float

the angle in radians of the rotation around the specified axis

getAngleRadback to summary
public float getAngleRad()

Get the angle in radians of the rotation this quaternion represents. Does not normalize the quaternion. Use getAxisAngleRad(Vector3) to get both the axis and the angle of this rotation. Use getAngleAroundRad(Vector3) to get the angle around a specific axis.

Returns:float

the angle in radians of the rotation

getAxisAngleback to summary
public float getAxisAngle(Vector3 axis)

Get the axis angle representation of the rotation in degrees. The supplied vector will receive the axis (x, y and z values) of the rotation and the value returned is the angle in degrees around that axis. Note that this method will alter the supplied vector, the existing value of the vector is ignored.

This will normalize this quaternion if needed. The received axis is a unit vector. However, if this is an identity quaternion (no rotation), then the length of the axis may be zero.
Parameters
axis:Vector3

vector which will receive the axis

Returns:float

the angle in degrees

See Also
wikipedia, calculation
getAxisAngleRadback to summary
public float getAxisAngleRad(Vector3 axis)

Get the axis-angle representation of the rotation in radians. The supplied vector will receive the axis (x, y and z values) of the rotation and the value returned is the angle in radians around that axis. Note that this method will alter the supplied vector, the existing value of the vector is ignored.

This will normalize this quaternion if needed. The received axis is a unit vector. However, if this is an identity quaternion (no rotation), then the length of the axis may be zero.
Parameters
axis:Vector3

vector which will receive the axis

Returns:float

the angle in radians

See Also
wikipedia, calculation
getGimbalPoleback to summary
public int getGimbalPole()

Get the pole of the gimbal lock, if any.

Returns:int

positive (+1) for north pole, negative (-1) for south pole, zero (0) when no gimbal lock

getPitchback to summary
public float getPitch()

Get the pitch euler angle in degrees, which is the rotation around the x axis. Requires that this quaternion is normalized.

Returns:float

the rotation around the x axis in degrees (between -90 and +90)

getPitchRadback to summary
public float getPitchRad()

Get the pitch euler angle in radians, which is the rotation around the x axis. Requires that this quaternion is normalized.

Returns:float

the rotation around the x axis in radians (between -(PI/2) and +(PI/2))

getRollback to summary
public float getRoll()

Get the roll euler angle in degrees, which is the rotation around the z axis. Requires that this quaternion is normalized.

Returns:float

the rotation around the z axis in degrees (between -180 and +180)

getRollRadback to summary
public float getRollRad()

Get the roll euler angle in radians, which is the rotation around the z axis. Requires that this quaternion is normalized.

Returns:float

the rotation around the z axis in radians (between -PI and +PI)

getSwingTwistback to summary
public void getSwingTwist(final float axisX, final float axisY, final float axisZ, final Quaternion swing, final Quaternion twist)

Get the swing rotation and twist rotation for the specified axis. The twist rotation represents the rotation around the specified axis. The swing rotation represents the rotation of the specified axis itself, which is the rotation around an axis perpendicular to the specified axis.

The swing and twist rotation can be used to reconstruct the original quaternion: this = swing * twist
Parameters
axisX:float

the X component of the normalized axis for which to get the swing and twist rotation

axisY:float

the Y component of the normalized axis for which to get the swing and twist rotation

axisZ:float

the Z component of the normalized axis for which to get the swing and twist rotation

swing:Quaternion

will receive the swing rotation: the rotation around an axis perpendicular to the specified axis

twist:Quaternion

will receive the twist rotation: the rotation around the specified axis

See Also
calculation
getSwingTwistback to summary
public void getSwingTwist(final Vector3 axis, final Quaternion swing, final Quaternion twist)

Get the swing rotation and twist rotation for the specified axis. The twist rotation represents the rotation around the specified axis. The swing rotation represents the rotation of the specified axis itself, which is the rotation around an axis perpendicular to the specified axis.

The swing and twist rotation can be used to reconstruct the original quaternion: this = swing * twist
Parameters
axis:Vector3

the normalized axis for which to get the swing and twist rotation

swing:Quaternion

will receive the swing rotation: the rotation around an axis perpendicular to the specified axis

twist:Quaternion

will receive the twist rotation: the rotation around the specified axis

See Also
calculation
getYawback to summary
public float getYaw()

Get the yaw euler angle in degrees, which is the rotation around the y axis. Requires that this quaternion is normalized.

Returns:float

the rotation around the y axis in degrees (between -180 and +180)

getYawRadback to summary
public float getYawRad()

Get the yaw euler angle in radians, which is the rotation around the y axis. Requires that this quaternion is normalized.

Returns:float

the rotation around the y axis in radians (between -PI and +PI)

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Annotations
@Override
idtback to summary
public Quaternion idt()

Sets the quaternion to an identity Quaternion

Returns:Quaternion

this quaternion for chaining

isIdentityback to summary
public boolean isIdentity()
Returns:boolean

If this quaternion is an identity Quaternion

isIdentityback to summary
public boolean isIdentity(final float tolerance)
Returns:boolean

If this quaternion is an identity Quaternion

lenback to summary
public static final float len(final float x, final float y, final float z, final float w)
Returns:float

the euclidean length of the specified quaternion

lenback to summary
public float len()
Returns:float

the euclidean length of this quaternion

len2back to summary
public static final float len2(final float x, final float y, final float z, final float w)
len2back to summary
public float len2()
Returns:float

the length of this quaternion without square root

mulback to summary
public Quaternion mul(final Quaternion other)

Multiplies this quaternion with another one in the form of this = this * other

Parameters
other:Quaternion

Quaternion to multiply with

Returns:Quaternion

This quaternion for chaining

mulback to summary
public Quaternion mul(final float x, final float y, final float z, final float w)

Multiplies this quaternion with another one in the form of this = this * other

Parameters
x:float

the x component of the other quaternion to multiply with

y:float

the y component of the other quaternion to multiply with

z:float

the z component of the other quaternion to multiply with

w:float

the w component of the other quaternion to multiply with

Returns:Quaternion

This quaternion for chaining

mulback to summary
public Quaternion mul(float scalar)

Multiplies the components of this quaternion with the given scalar.

Parameters
scalar:float

the scalar.

Returns:Quaternion

this quaternion for chaining.

mulLeftback to summary
public Quaternion mulLeft(Quaternion other)

Multiplies this quaternion with another one in the form of this = other * this

Parameters
other:Quaternion

Quaternion to multiply with

Returns:Quaternion

This quaternion for chaining

mulLeftback to summary
public Quaternion mulLeft(final float x, final float y, final float z, final float w)

Multiplies this quaternion with another one in the form of this = other * this

Parameters
x:float

the x component of the other quaternion to multiply with

y:float

the y component of the other quaternion to multiply with

z:float

the z component of the other quaternion to multiply with

w:float

the w component of the other quaternion to multiply with

Returns:Quaternion

This quaternion for chaining

norback to summary
public Quaternion nor()

Normalizes this quaternion to unit length

Returns:Quaternion

the quaternion for chaining

setback to summary
public Quaternion set(float x, float y, float z, float w)

Sets the components of the quaternion

Parameters
x:float

The x-component

y:float

The y-component

z:float

The z-component

w:float

The w-component

Returns:Quaternion

This quaternion for chaining

setback to summary
public Quaternion set(Quaternion quaternion)

Sets the quaternion components from the given quaternion.

Parameters
quaternion:Quaternion

The quaternion.

Returns:Quaternion

This quaternion for chaining.

setback to summary
public Quaternion set(Vector3 axis, float angle)

Sets the quaternion components from the given axis and angle around that axis.

Parameters
axis:Vector3

The axis

angle:float

The angle in degrees

Returns:Quaternion

This quaternion for chaining.

setEulerAnglesback to summary
public Quaternion setEulerAngles(float yaw, float pitch, float roll)

Sets the quaternion to the given euler angles in degrees.

Parameters
yaw:float

the rotation around the y axis in degrees

pitch:float

the rotation around the x axis in degrees

roll:float

the rotation around the z axis degrees

Returns:Quaternion

this quaternion

setEulerAnglesRadback to summary
public Quaternion setEulerAnglesRad(float yaw, float pitch, float roll)

Sets the quaternion to the given euler angles in radians.

Parameters
yaw:float

the rotation around the y axis in radians

pitch:float

the rotation around the x axis in radians

roll:float

the rotation around the z axis in radians

Returns:Quaternion

this quaternion

setFromAxesback to summary
public Quaternion setFromAxes(float xx, float xy, float xz, float yx, float yy, float yz, float zx, float zy, float zz)

Sets the Quaternion from the given x-, y- and z-axis which have to be orthonormal.

Taken from Bones framework for JPCT, see http://www.aptalkarga.com/bones/ which in turn took it from Graphics Gem code at ftp://ftp.cis.upenn.edu/pub/graphics/shoemake/quatut.ps.Z.

Parameters
xx:float

x-axis x-coordinate

xy:float

x-axis y-coordinate

xz:float

x-axis z-coordinate

yx:float

y-axis x-coordinate

yy:float

y-axis y-coordinate

yz:float

y-axis z-coordinate

zx:float

z-axis x-coordinate

zy:float

z-axis y-coordinate

zz:float

z-axis z-coordinate

setFromAxesback to summary
public Quaternion setFromAxes(boolean normalizeAxes, float xx, float xy, float xz, float yx, float yy, float yz, float zx, float zy, float zz)

Sets the Quaternion from the given x-, y- and z-axis.

Taken from Bones framework for JPCT, see http://www.aptalkarga.com/bones/ which in turn took it from Graphics Gem code at ftp://ftp.cis.upenn.edu/pub/graphics/shoemake/quatut.ps.Z.

Parameters
normalizeAxes:boolean

whether to normalize the axes (necessary when they contain scaling)

xx:float

x-axis x-coordinate

xy:float

x-axis y-coordinate

xz:float

x-axis z-coordinate

yx:float

y-axis x-coordinate

yy:float

y-axis y-coordinate

yz:float

y-axis z-coordinate

zx:float

z-axis x-coordinate

zy:float

z-axis y-coordinate

zz:float

z-axis z-coordinate

setFromAxisback to summary
public Quaternion setFromAxis(final Vector3 axis, final float degrees)

Sets the quaternion components from the given axis and angle around that axis.

Parameters
axis:Vector3

The axis

degrees:float

The angle in degrees

Returns:Quaternion

This quaternion for chaining.

setFromAxisback to summary
public Quaternion setFromAxis(final float x, final float y, final float z, final float degrees)

Sets the quaternion components from the given axis and angle around that axis.

Parameters
x:float

X direction of the axis

y:float

Y direction of the axis

z:float

Z direction of the axis

degrees:float

The angle in degrees

Returns:Quaternion

This quaternion for chaining.

setFromAxisRadback to summary
public Quaternion setFromAxisRad(final Vector3 axis, final float radians)

Sets the quaternion components from the given axis and angle around that axis.

Parameters
axis:Vector3

The axis

radians:float

The angle in radians

Returns:Quaternion

This quaternion for chaining.

setFromAxisRadback to summary
public Quaternion setFromAxisRad(final float x, final float y, final float z, final float radians)

Sets the quaternion components from the given axis and angle around that axis.

Parameters
x:float

X direction of the axis

y:float

Y direction of the axis

z:float

Z direction of the axis

radians:float

The angle in radians

Returns:Quaternion

This quaternion for chaining.

setFromCrossback to summary
public Quaternion setFromCross(final Vector3 v1, final Vector3 v2)

Set this quaternion to the rotation between two vectors.

Parameters
v1:Vector3

The base vector, which should be normalized.

v2:Vector3

The target vector, which should be normalized.

Returns:Quaternion

This quaternion for chaining

setFromCrossback to summary
public Quaternion setFromCross(final float x1, final float y1, final float z1, final float x2, final float y2, final float z2)

Set this quaternion to the rotation between two vectors.

Parameters
x1:float

The base vectors x value, which should be normalized.

y1:float

The base vectors y value, which should be normalized.

z1:float

The base vectors z value, which should be normalized.

x2:float

The target vector x value, which should be normalized.

y2:float

The target vector y value, which should be normalized.

z2:float

The target vector z value, which should be normalized.

Returns:Quaternion

This quaternion for chaining

setFromMatrixback to summary
public Quaternion setFromMatrix(boolean normalizeAxes, Matrix4 matrix)

Sets the Quaternion from the given matrix, optionally removing any scaling.

setFromMatrixback to summary
public Quaternion setFromMatrix(Matrix4 matrix)

Sets the Quaternion from the given rotation matrix, which must not contain scaling.

setFromMatrixback to summary
public Quaternion setFromMatrix(boolean normalizeAxes, Matrix3 matrix)

Sets the Quaternion from the given matrix, optionally removing any scaling.

setFromMatrixback to summary
public Quaternion setFromMatrix(Matrix3 matrix)

Sets the Quaternion from the given rotation matrix, which must not contain scaling.

slerpback to summary
public Quaternion slerp(Quaternion end, float alpha)

Spherical linear interpolation between this quaternion and the other quaternion, based on the alpha value in the range [0,1]. Taken from Bones framework for JPCT, see http://www.aptalkarga.com/bones/

Parameters
end:Quaternion

the end quaternion

alpha:float

alpha in the range [0,1]

Returns:Quaternion

this quaternion for chaining

slerpback to summary
public Quaternion slerp(Quaternion[] q)

Spherical linearly interpolates multiple quaternions and stores the result in this Quaternion. Will not destroy the data previously inside the elements of q. result = (q_1^w_1)*(q_2^w_2)* ... *(q_n^w_n) where w_i=1/n.

Parameters
q:Quaternion[]

List of quaternions

Returns:Quaternion

This quaternion for chaining

slerpback to summary
public Quaternion slerp(Quaternion[] q, float[] w)

Spherical linearly interpolates multiple quaternions by the given weights and stores the result in this Quaternion. Will not destroy the data previously inside the elements of q or w. result = (q_1^w_1)*(q_2^w_2)* ... *(q_n^w_n) where the sum of w_i is 1. Lists must be equal in length.

Parameters
q:Quaternion[]

List of quaternions

w:float[]

List of weights

Returns:Quaternion

This quaternion for chaining

toMatrixback to summary
public void toMatrix(final float[] matrix)

Fills a 4x4 matrix with the rotation matrix represented by this quaternion.

Parameters
matrix:float[]

Matrix to fill

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
transformback to summary
public Vector3 transform(Vector3 v)

Transforms the given vector using this quaternion

Parameters
v:Vector3

Vector to transform