Atavism Version 2018.1AGIS API

atavism.server.math
Class Quaternion

java.lang.Object
  extended by atavism.server.math.Quaternion
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
RotateTransform

public class Quaternion
extends java.lang.Object
implements java.io.Externalizable, java.lang.Cloneable

this object is not thread safe

See Also:
Serialized Form

Field Summary
static float epsilon
           
static Quaternion Identity
           
 
Constructor Summary
Quaternion()
          no args constructor sets w to 1.0, all others 0
Quaternion(float x, float y, float z, float w)
           
Quaternion(Quaternion other)
           
 
Method Summary
static float clamp(float value, float min, float max)
           
 java.lang.Object clone()
           
 boolean equals(java.lang.Object obj)
           
 boolean equals(Quaternion q)
           
static Quaternion fromAngleAxis(double angle, AOVector axis)
          Create a quaternion from a supplied angle and axis
static Quaternion fromAngleAxisDegrees(double angle, AOVector axis)
          Create a quaternion from a supplied angle and axis
static Quaternion fromTwoVectors(AOVector u, AOVector v)
           
static Quaternion fromVectorRotation(AOVector a, AOVector b)
          Create a new quaternion that will rotate vector a into vector b about their mutually perpendicular axis.
 double getAngleAxis(AOVector axis)
          Get the axis of rotation and the angle for this quaternion
 double getAngleAxisDegrees(AOVector axis)
          Get the axis of rotation and the angle for this quaternion
 int getGimbalPole()
          Get the pole of the gimbal lock, if any.
 float getPitch()
          Get the pitch euler angle in degrees, which is the rotation around the x axis.
 float getPitchRad()
          Get the pitch euler angle in radians, which is the rotation around the x axis.
 float getRoll()
          Get the roll euler angle in degrees, which is the rotation around the z axis.
 float getRollRad()
          Get the roll euler angle in radians, which is the rotation around the z axis.
 float getW()
           
 float getX()
           
 AOVector getXAxis()
           
 float getY()
           
 float getYaw()
          Get the yaw euler angle in degrees, which is the rotation around the y axis.
 float getYawRad()
          Get the yaw euler angle in radians, which is the rotation around the y axis.
 AOVector getYAxis()
           
 float getZ()
           
 AOVector getZAxis()
           
 float len()
           
 float len2()
           
static AOVector multiply(Quaternion quat, AOVector vector)
           
static Quaternion multiply(Quaternion left, Quaternion right)
          Multiply two quaternions
 Quaternion normalize()
          Normalizes this quaternion to unit length
static Quaternion parseQuaternion(java.lang.String s)
           
 void readExternal(java.io.ObjectInput in)
           
 Quaternion setEulerAngles(float pitch, float yaw, float roll)
          Sets the quaternion to the given euler angles in degrees.
 Quaternion setEulerAnglesRad(float pitch, float yaw, float roll)
          Sets the quaternion to the given euler angles in radians.
 void setW(float w)
           
 void setX(float x)
           
 void setY(float y)
           
 void setZ(float z)
           
 AOVector toEulerAngles()
          Returns the Euler Angle representation of this Quaternion in radians.
 java.lang.String toString()
           
 void writeExternal(java.io.ObjectOutput out)
           
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

Identity

public static final Quaternion Identity

epsilon

public static float epsilon
Constructor Detail

Quaternion

public Quaternion()
no args constructor sets w to 1.0, all others 0


Quaternion

public Quaternion(float x,
                  float y,
                  float z,
                  float w)

Quaternion

public Quaternion(Quaternion other)
Method Detail

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

parseQuaternion

public static Quaternion parseQuaternion(java.lang.String s)

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

equals

public boolean equals(Quaternion q)

getX

public float getX()

getY

public float getY()

getZ

public float getZ()

getW

public float getW()

setX

public void setX(float x)

setY

public void setY(float y)

setZ

public void setZ(float z)

setW

public void setW(float w)

fromAngleAxis

public static Quaternion fromAngleAxis(double angle,
                                       AOVector axis)
Create a quaternion from a supplied angle and axis

Parameters:
angle - angle in radians
axis - axis vector about which to rotate
Returns:
a quaternion based on the axis and angle

fromAngleAxisDegrees

public static Quaternion fromAngleAxisDegrees(double angle,
                                              AOVector axis)
Create a quaternion from a supplied angle and axis

Parameters:
angle - angle in degrees
axis - axis vector about which to rotate
Returns:
a quaternion based on the axis and angle

getAngleAxisDegrees

public double getAngleAxisDegrees(AOVector axis)
Get the axis of rotation and the angle for this quaternion

Parameters:
axis - reference to axis vector which will be populated with axis of rotation.
Returns:
angle in degrees

getAngleAxis

public double getAngleAxis(AOVector axis)
Get the axis of rotation and the angle for this quaternion

Parameters:
axis - reference to axis vector which will be populated with axis of rotation.
Returns:
angle in degrees

fromVectorRotation

public static Quaternion fromVectorRotation(AOVector a,
                                            AOVector b)
Create a new quaternion that will rotate vector a into vector b about their mutually perpendicular axis.

Parameters:
a - starting facing
b - ending facing

fromTwoVectors

public static Quaternion fromTwoVectors(AOVector u,
                                        AOVector v)

multiply

public static Quaternion multiply(Quaternion left,
                                  Quaternion right)
Multiply two quaternions

Parameters:
left - the quaternion on the left
right - the quaternion on the right
Returns:
the product of left * right

multiply

public static AOVector multiply(Quaternion quat,
                                AOVector vector)

setEulerAngles

public Quaternion setEulerAngles(float pitch,
                                 float yaw,
                                 float roll)
Sets the quaternion to the given euler angles in degrees.

Parameters:
pitch - the rotation around the x axis in degrees
yaw - the rotation around the y axis in degrees
roll - the rotation around the z axis degrees
Returns:
this quaternion

setEulerAnglesRad

public Quaternion setEulerAnglesRad(float pitch,
                                    float yaw,
                                    float roll)
Sets the quaternion to the given euler angles in radians.

Parameters:
pitch - the rotation around the x axis in radians
yaw - the rotation around the y axis in radians
roll - the rotation around the z axis in radians
Returns:
this quaternion

toEulerAngles

public AOVector toEulerAngles()
Returns the Euler Angle representation of this Quaternion in radians.

Returns:

getXAxis

public AOVector getXAxis()

getYAxis

public AOVector getYAxis()

getZAxis

public AOVector getZAxis()

getGimbalPole

public int getGimbalPole()
Get the pole of the gimbal lock, if any.

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

getRollRad

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:
the rotation around the z axis in radians (between -PI and +PI)

getRoll

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:
the rotation around the z axis in degrees (between -180 and +180)

getPitchRad

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:
the rotation around the x axis in radians (between -(PI/2) and +(PI/2))

getPitch

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:
the rotation around the x axis in degrees (between -90 and +90)

getYawRad

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:
the rotation around the y axis in radians (between -PI and +PI)

getYaw

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:
the rotation around the y axis in degrees (between -180 and +180)

clamp

public static float clamp(float value,
                          float min,
                          float max)

len

public float len()
Returns:
the euclidian length of this quaternion

len2

public float len2()
Returns:
the length of this quaternion without square root

normalize

public Quaternion normalize()
Normalizes this quaternion to unit length

Returns:
the quaternion for chaining

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Specified by:
writeExternal in interface java.io.Externalizable
Throws:
java.io.IOException

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Specified by:
readExternal in interface java.io.Externalizable
Throws:
java.io.IOException
java.lang.ClassNotFoundException


Copyright © 2018 Dragonsan Studios Sp. z o.o.