Package pamMaths

Class PamQuaternion

java.lang.Object
pamMaths.PamQuaternion
All Implemented Interfaces:
Serializable, Cloneable

public class PamQuaternion extends Object implements Cloneable, Serializable
Basically a quaternion is a vector which can encode three dimensional orientation information (e.g. heading, pitch and roll). Means we can get rid of Euler angles if we want to. This particular qauternion class assumes that the heading rotates around the z-axis, pitch rotates around the x-axis and roll rotates around the y-axis.

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

    Fields
    Modifier and Type
    Field
    Description
    static 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

    Constructors
    Constructor
    Description
    PamQuaternion(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 Type
    Method
    Description
     
    static double[]
    fromEulerAngles(double heading, double pitch, double roll)
    Create a quaternion from euler angles.
    static double[]
    fromEulerAnglesb(double heading, double pitch, double roll)
     
    fromRotation(Jama.Matrix m)
     
    fromTransform(Jama.Matrix t)
     
    double[]
    Access the components of the quaternion.
    double
    Access the w-component (scalar) of the quaternion.
    double
    Access the x-component ("i") of the quaternion.
    double
    Access the y-component ("j") of the quaternion.
    double
    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
    Returns the roll component of the quaternion if it is represented as standard roll-pitch-yaw Euler angles.
    double
    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.
     
    Jama.Matrix
     

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • serialVersionUID

      public static final long serialVersionUID
      Determines 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_POLE
      This defines the north pole singularity cutoff when converting from quaternions to Euler angles.
      See Also:
    • SINGULARITY_SOUTH_POLE

      public static final double SINGULARITY_SOUTH_POLE
      This 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 object
      x - the x-coordinate of the object
      y - the y-coordinate of the object
      z - 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 RADIANS
      pitch - - 90->90 degrees. Input in RADIANS
      roll - -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

      public static PamQuaternion fromRotation(Jama.Matrix m)
    • toRotation

      public Jama.Matrix toRotation()
      Converts quaternion to (3x3) rotation matrix.
      Returns:
      a 2D 3x3 rotation matrix representing the quaternion.
    • fromTransform

      public static PamQuaternion fromTransform(Jama.Matrix t)
    • 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 RADIANS
      pitch - 90->90 degrees. Input in RADIANS
      roll - 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

      public PamQuaternion clone()
    • toString

      public String toString()
      Overrides:
      toString in class Object