Class PamQuaternion
- All Implemented Interfaces:
Serializable
,Cloneable
Wikipedia Description 15/11/2013
Unit quaternions, also known as versors, provide a convenient mathematical notation for representing orientations and rotations of objects in three dimensions. Compared to Euler angles they are simpler to compose and avoid the problem of gimbal lock. Compared to rotation matrices they are more numerically stable and may be more efficient. Quaternions have found their way into applications in computer graphics, computer vision, robotics, navigation, molecular dynamics, flight dynamics,[1] and orbital mechanics of satellites
Code is heavily based on code from Prasanna Velagapudi. Copyright (c) 2008, Prasanna Velagapudi invalid input: '<'pkv@cs.cmu.edu>. Permission to use, modify and distribute. https://github.com/psigen/robotutils/blob/master/src/main/java/robotutils/Quaternion.java
Note this code is also available in the apache common 3+ library. PAMGUARD currently implements the Apache 2.2 library so have made unique class.
- Author:
- Prasanna Velagapudi. Modified by Jamie Macaulay to use Jama and support the PAMGUARD vector and orientation conventions.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final long
Determines if a de-serialized object is compatible with this class.static final double
This defines the north pole singularity cutoff when converting from quaternions to Euler angles.static final double
This defines the south pole singularity cutoff when converting from quaternions to Euler angles. -
Constructor Summary
ConstructorDescriptionPamQuaternion
(double[] q) Wrap a quaternion in vector form.PamQuaternion
(double heading, double pitch, double roll) Create a quartenion from euler angles.PamQuaternion
(double w, double x, double y, double z) Construct a new quaternion. -
Method Summary
Modifier and TypeMethodDescriptionclone()
static double[]
fromEulerAngles
(double heading, double pitch, double roll) Create a quaternion from euler angles.static double[]
fromEulerAnglesb
(double heading, double pitch, double roll) static PamQuaternion
fromRotation
(Jama.Matrix m) static PamQuaternion
fromTransform
(Jama.Matrix t) double[]
getArray()
Access the components of the quaternion.double
getW()
Access the w-component (scalar) of the quaternion.double
getX()
Access the x-component ("i") of the quaternion.double
getY()
Access the y-component ("j") of the quaternion.double
getZ()
Access the z-component ("k") of the quaternion.double[]
Returns the components of the quaternion if it is represented as standard roll-pitch-yaw Euler angles.double
Returns the yaw component of the quaternion if it is represented as standard roll-pitch-yaw Euler angles.double
toPitch()
Returns the roll component of the quaternion if it is represented as standard roll-pitch-yaw Euler angles.double
toRoll()
Returns the pitch component of the quaternion if it is represented as standard roll-pitch-yaw Euler angles.Jama.Matrix
Converts quaternion to (3x3) rotation matrix.toString()
Jama.Matrix
-
Field Details
-
serialVersionUID
public static final long serialVersionUIDDetermines if a de-serialized object is compatible with this class. Maintainers must change this value if and only if the new version of this class is not compatible with old versions. See Sun docs for invalid input: '<'a href=http://java.sun.com/products/jdk/1.1/docs/guide /serialization/spec/version.doc.html> details.- See Also:
-
SINGULARITY_NORTH_POLE
public static final double SINGULARITY_NORTH_POLEThis defines the north pole singularity cutoff when converting from quaternions to Euler angles.- See Also:
-
SINGULARITY_SOUTH_POLE
public static final double SINGULARITY_SOUTH_POLEThis defines the south pole singularity cutoff when converting from quaternions to Euler angles.- See Also:
-
-
Constructor Details
-
PamQuaternion
public PamQuaternion(double w, double x, double y, double z) Construct a new quaternion.- Parameters:
w
- the w-coordinate of the objectx
- the x-coordinate of the objecty
- the y-coordinate of the objectz
- the z-coordinate of the object
-
PamQuaternion
public PamQuaternion(double[] q) Wrap a quaternion in vector form.- Parameters:
q
- a quaternion vector in {w, x, y, z} form.
-
PamQuaternion
public PamQuaternion(double heading, double pitch, double roll) Create a quartenion from euler angles.- Parameters:
heading
- -0-360 degrees. Input in RADIANSpitch
- - 90->90 degrees. Input in RADIANSroll
- -0->180 and 0->-180. Input in RADIANS
-
-
Method Details
-
getW
public double getW()Access the w-component (scalar) of the quaternion.- Returns:
- the w-component of the quaternion.
-
getX
public double getX()Access the x-component ("i") of the quaternion.- Returns:
- the x-component of the quaternion.
-
getY
public double getY()Access the y-component ("j") of the quaternion.- Returns:
- the y-component of the quaternion.
-
getZ
public double getZ()Access the z-component ("k") of the quaternion.- Returns:
- the z-component of the quaternion.
-
getArray
public double[] getArray()Access the components of the quaternion.- Returns:
- the components of the quaternion in {w, x, y, z} form.
-
fromRotation
-
toRotation
public Jama.Matrix toRotation()Converts quaternion to (3x3) rotation matrix.- Returns:
- a 2D 3x3 rotation matrix representing the quaternion.
-
fromTransform
-
toTransform
public Jama.Matrix toTransform() -
fromEulerAngles
public static double[] fromEulerAngles(double heading, double pitch, double roll) Create a quaternion from euler angles.- Parameters:
heading
- 0-360 degrees. Input in RADIANSpitch
- 90->90 degrees. Input in RADIANSroll
- 0->180 and 0->-180.- Returns:
-
fromEulerAnglesb
public static double[] fromEulerAnglesb(double heading, double pitch, double roll) -
toPitch
public double toPitch()Returns the roll component of the quaternion if it is represented as standard roll-pitch-yaw Euler angles.- Returns:
- the roll (x-axis rotation) of the robot.
-
toRoll
public double toRoll()Returns the pitch component of the quaternion if it is represented as standard roll-pitch-yaw Euler angles.- Returns:
- the pitch (y-axis rotation) of the robot.
-
toHeading
public double toHeading()Returns the yaw component of the quaternion if it is represented as standard roll-pitch-yaw Euler angles.- Returns:
- the yaw (z-axis rotation) in RADIANS
-
toEulerAngles
public double[] toEulerAngles()Returns the components of the quaternion if it is represented as standard roll-pitch-yaw Euler angles.- Returns:
- an array of the form {roll, pitch, yaw}.
-
clone
-
toString
-