Class AxisRotation3D

java.lang.Object
com.irurueta.geometry.Rotation3D
com.irurueta.geometry.AxisRotation3D
All Implemented Interfaces:
Serializable

public class AxisRotation3D extends Rotation3D implements Serializable
This class defines the amount of rotation for 3D points or planes. Rotation is defined internally as axis coordinates and rotation angle, following Rodrigues formulas. This class is based in: http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/sfrotation_java.htm
See Also:
  • Field Details

    • AXIS_PARAMS

      public static final int AXIS_PARAMS
      Number of parameters defining a rotation axis.
      See Also:
    • EPS

      public static final double EPS
      Constant defining machine precision.
      See Also:
    • axisX

      private double axisX
      x element of axis angle.
    • axisY

      private double axisY
      y element of axis angle.
    • axisZ

      private double axisZ
      z element of axis angle.
    • theta

      private double theta
      angle element of axis angle.
  • Constructor Details

    • AxisRotation3D

      public AxisRotation3D(double axisX, double axisY, double axisZ, double theta)
      Constructor which allows initial value to be supplied as axis and angle. For better accuracy, axis values should be normalized.
      Parameters:
      axisX - x dimension of normalized axis.
      axisY - y dimension of normalized axis.
      axisZ - z dimension of normalized axis.
      theta - angle in radians.
    • AxisRotation3D

      public AxisRotation3D(double[] axis, double theta)
      Constructor where array of axis values and rotation angle are provided For better accuracy, axis values should be normalized.
      Parameters:
      axis - Array containing x,y and z values of axis.
      theta - rotation angle in radians.
      Throws:
      IllegalArgumentException - if provided axis length is not 3.
    • AxisRotation3D

      public AxisRotation3D(AxisRotation3D rotation)
      Copy constructor.
      Parameters:
      rotation - instance to copy.
    • AxisRotation3D

      public AxisRotation3D(Rotation3D rot)
      Copy constructor.
      Parameters:
      rot - Converts and copies provided rotation instance.
    • AxisRotation3D

      public AxisRotation3D()
      Empty constructor.
  • Method Details

    • getType

      public Rotation3DType getType()
      Returns type of this rotation.
      Specified by:
      getType in class Rotation3D
      Returns:
      Type of this rotation.
    • fromRotation

      public final void fromRotation(AxisRotation3D rot)
      Sets rotation of this instance by copying provided rotation.
      Overrides:
      fromRotation in class Rotation3D
      Parameters:
      rot - Rotation to be copied.
    • setAxis

      public void setAxis(double axisX, double axisY, double axisZ)
      Sets rotation axis of this instance while preserving the rotation angle. Once set, points will rotate around provided axis.
      Parameters:
      axisX - X coordinate of rotation axis.
      axisY - Y coordinate of rotation axis.
      axisZ - Z coordinate of rotation axis.
    • setAxisAndRotation

      public final void setAxisAndRotation(double axisX, double axisY, double axisZ, double theta)
      Sets the axis and rotation of this instance. Once set, points will rotate around provided axis an amount equal to provided rotation angle in radians. Note: to avoid numerical instabilities and improve accuracy, axis coordinates should be normalized (e.g. norm equal to 1).
      Specified by:
      setAxisAndRotation in class Rotation3D
      Parameters:
      axisX - X coordinate of rotation axis.
      axisY - Y coordinate of rotation axis.
      axisZ - Z coordinate of rotation axis.
      theta - Amount of rotation in radians.
    • getAxisX

      public double getAxisX()
      Returns X coordinate of rotation axis.
      Returns:
      X coordinate of rotation axis.
    • getAxisY

      public double getAxisY()
      Returns Y coordinate of rotation axis.
      Returns:
      Y coordinate of rotation axis.
    • getAxisZ

      public double getAxisZ()
      Returns Z coordinate of rotation axis.
      Returns:
      Z coordinate of rotation axis.
    • rotationAxis

      public void rotationAxis(double[] axis)
      Returns rotation axis corresponding to this instance. Result is stored in provided axis array, which must have length 3
      Specified by:
      rotationAxis in class Rotation3D
      Parameters:
      axis - Array where axis coordinates will be stored.
      Throws:
      IllegalArgumentException - Raised if provided array does not have length 3.
    • getRotationAngle

      public double getRotationAngle()
      Returns rotation amount or angle in radians around the rotation axis associated to this instance.
      Specified by:
      getRotationAngle in class Rotation3D
      Returns:
      Rotation angle in radians.
    • inverseRotationAndReturnNew

      public AxisRotation3D inverseRotationAndReturnNew()
      Returns a 3D rotation which is inverse to this instance. In other words, the combination of this rotation with its inverse produces no change.
      Specified by:
      inverseRotationAndReturnNew in class Rotation3D
      Returns:
      Inverse 3D rotation.
    • inverseRotation

      public void inverseRotation(AxisRotation3D result)
      Sets into provided MatrixRotation3D instance a rotation inverse to this instance. The combination of this rotation with its inverse produces no change.
      Parameters:
      result - Instance where inverse rotation will be set.
    • inverseRotation

      public void inverseRotation(Rotation3D result)
      Sets into provided MatrixRotation3D instance a rotation inverse to this instance. The combination of this rotation with its inverse produces no change.
      Specified by:
      inverseRotation in class Rotation3D
      Parameters:
      result - Instance where inverse rotation will be set.
    • inverseRotation

      public void inverseRotation()
      Reverses the rotation of this instance.
      Specified by:
      inverseRotation in class Rotation3D
    • asInhomogeneousMatrix

      public com.irurueta.algebra.Matrix asInhomogeneousMatrix()
      Returns this 3D rotation instance expressed as a 3x3 inhomogeneous matrix. This is equivalent to call getInternalMatrix().
      Specified by:
      asInhomogeneousMatrix in class Rotation3D
      Returns:
      Rotation matrix expressed in inhomogeneous coordinates.
    • asInhomogeneousMatrix

      public void asInhomogeneousMatrix(com.irurueta.algebra.Matrix result)
      Sets into provided Matrix instance this 3D rotation expressed as a 3x3 inhomogeneous matrix.
      Specified by:
      asInhomogeneousMatrix in class Rotation3D
      Parameters:
      result - Matrix where rotation will be set.
      Throws:
      IllegalArgumentException - Raised if provided instance does not have size 3x3.
    • asHomogeneousMatrix

      public com.irurueta.algebra.Matrix asHomogeneousMatrix()
      Returns this 3D rotation instance expressed as a 4x4 homogeneous matrix.
      Specified by:
      asHomogeneousMatrix in class Rotation3D
      Returns:
      Rotation matrix expressed in homogeneous coordinates.
    • asHomogeneousMatrix

      public void asHomogeneousMatrix(com.irurueta.algebra.Matrix result)
      Sets into provided Matrix instance this 3D rotation expressed as a 4x4 homogeneous matrix.
      Specified by:
      asHomogeneousMatrix in class Rotation3D
      Parameters:
      result - Matrix where rotation will be set.
      Throws:
      IllegalArgumentException - Raised if provided instance does not have size 4x4.
    • fromInhomogeneousMatrix

      public void fromInhomogeneousMatrix(com.irurueta.algebra.Matrix m, double threshold) throws InvalidRotationMatrixException
      Sets amount of rotation from provided inhomogeneous rotation matrix. Provided matrix must be orthogonal (i.e. squared, non-singular, it's transpose must be its inverse) and must have determinant equal to 1. Provided matrix must also have size 3x3.
      Specified by:
      fromInhomogeneousMatrix in class Rotation3D
      Parameters:
      m - Provided rotation matrix.
      threshold - Threshold to determine whether matrix is orthonormal.
      Throws:
      InvalidRotationMatrixException - Raised if provided matrix is not valid (has wrong size, or it is not orthonormal).
      IllegalArgumentException - Raised if provided threshold is negative Rotation3D.isValidRotationMatrix(Matrix)
    • fromHomogeneousMatrix

      public void fromHomogeneousMatrix(com.irurueta.algebra.Matrix m, double threshold) throws InvalidRotationMatrixException
      Sets amount of rotation from provided homogeneous rotation matrix. Provided matrix must be orthogonal (i.e. squared, non-singular, it's transpose must be its inverse) and must have determinant equal to 1. Provided matrix must also have size 4x4, and its last row and column must be zero, except for element in last row and column which must be 1.
      Specified by:
      fromHomogeneousMatrix in class Rotation3D
      Parameters:
      m - Provided rotation matrix.
      threshold - Threshold to determine whether matrix is orthonormal.
      Throws:
      InvalidRotationMatrixException - Raised if provided matrix is not valid (has wrong size, or it is not orthonormal).
      IllegalArgumentException - Raised if provided threshold is negative. Rotation3D.isValidRotationMatrix(Matrix).
    • rotate

      public void rotate(Point3D inputPoint, Point3D resultPoint)
      Rotates a 3D point using the origin of coordinates as the axis of rotation. Point will be rotated by the amount of rotation contained in this instance.
      Specified by:
      rotate in class Rotation3D
      Parameters:
      inputPoint - Input point to be rotated.
      resultPoint - Rotated point.
    • combineAndReturnNew

      public AxisRotation3D combineAndReturnNew(AxisRotation3D rotation)
      Combines provided rotation with this rotation and returns the result as a new MatrixRotation3D instance.
      Parameters:
      rotation - Input rotation to be combined.
      Returns:
      Combined rotation, which is equal to the multiplication of the internal matrix of provided rotation with the internal matrix of this instance.
    • combineAndReturnNew

      public Rotation3D combineAndReturnNew(Rotation3D rotation)
      Combines provided rotation with this rotation and returns the result as a new MatrixRotation3D instance.
      Specified by:
      combineAndReturnNew in class Rotation3D
      Parameters:
      rotation - Input rotation to be combined.
      Returns:
      Combined rotation, which is equal to the multiplication of the internal matrix of provided rotation with the internal matrix of this instance.
    • combine

      public void combine(AxisRotation3D rotation)
      Combines provided rotation into this rotation resulting in the multiplication of the internal matrices of both rotations.
      Parameters:
      rotation - Input rotation to be combined.
    • combine

      public void combine(Rotation3D rotation)
      Combines provided rotation into this rotation resulting in the multiplication of the internal matrices of both rotations.
      Specified by:
      combine in class Rotation3D
      Parameters:
      rotation - Input rotation to be combined.
    • combine

      public static void combine(AxisRotation3D rot1, AxisRotation3D rot2, AxisRotation3D result)
      Combines the rotation of instances rot1 and rot1 into provided result instance.
      Parameters:
      rot1 - 1st input rotation.
      rot2 - 2nd input rotation.
      result - Combined rotation, which is equal to the multiplication of the internal matrix of provided rotation with the internal matrix of this instance.
    • fromRotation

      public void fromRotation(Quaternion q)
      Sets values of this rotation from a quaternion.
      Specified by:
      fromRotation in class Rotation3D
      Parameters:
      q - a quaternion to set values from.
    • toMatrixRotation

      public void toMatrixRotation(MatrixRotation3D result)
      Converts this 3D rotation into a matrix rotation storing the result into provided instance.
      Overrides:
      toMatrixRotation in class Rotation3D
      Parameters:
      result - instance where result wil be stored.
    • toAxisRotation

      public void toAxisRotation(AxisRotation3D result)
      Converts this 3D rotation into an axis rotation storing the result into provided instance.
      Overrides:
      toAxisRotation in class Rotation3D
      Parameters:
      result - instance where result will be stored.
    • toQuaternion

      public void toQuaternion(Quaternion result)
      Converts this 3D rotation into a quaternion storing the result into provided instance.
      Overrides:
      toQuaternion in class Rotation3D
      Parameters:
      result - instance where result will be stored.