Package com.irurueta.geometry
Class MatrixRotation3D
java.lang.Object
com.irurueta.geometry.Rotation3D
com.irurueta.geometry.MatrixRotation3D
- All Implemented Interfaces:
Serializable
This class defines the amount of rotation for 3D points or planes.
Rotation is defined internally as a matrix.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doubleThreshold to determine that a gimbal locked might have been achieved when trying to find roll, pitch and yaw angles.protected com.irurueta.algebra.MatrixInternal matrix containing rotation using inhomogeneous coordinates.static final intConstant defining the number of columns on a 3D rotation matrix expressed in homogeneous coordinates.static final intConstant defining the number of rows on a 3D rotation matrix expressed in homogeneous coordinates.static final intConstant defining the number of columns on a 3D rotation matrix expressed in inhomogeneous coordinates.static final intConstant defining the number of rows on a 3D rotation matrix expressed in inhomogeneous coordinates.Fields inherited from class com.irurueta.geometry.Rotation3D
DEFAULT_COMPARISON_THRESHOLD, DEFAULT_TYPE, DEFAULT_VALID_THRESHOLD, HOM_COORDS, INHOM_COORDS, MIN_THRESHOLD -
Constructor Summary
ConstructorsConstructorDescriptionEmpty Constructor.MatrixRotation3D(double[] axis, double theta) Constructor.MatrixRotation3D(double alphaEuler, double betaEuler, double gammaEuler) Constructor.MatrixRotation3D(double axisX, double axisY, double axisZ, double theta) Constructor.MatrixRotation3D(com.irurueta.algebra.Matrix m) Constructor.MatrixRotation3D(com.irurueta.algebra.Matrix m, double threshold) Constructor.MatrixRotation3D(MatrixRotation3D rotation) Copy constructor.MatrixRotation3D(Rotation3D rotation) Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptioncom.irurueta.algebra.MatrixReturns this 3D rotation instance expressed as a 4x4 homogeneous matrix.voidasHomogeneousMatrix(com.irurueta.algebra.Matrix result) Sets into provided Matrix instance this 3D rotation expressed as a 4x4 homogeneous matrix.com.irurueta.algebra.MatrixReturns this 3D rotation instance expressed as a 3x3 inhomogeneous matrix.voidasInhomogeneousMatrix(com.irurueta.algebra.Matrix result) Sets into provided Matrix instance this 3D rotation expressed as a 3x3 inhomogeneous matrix.voidcombine(MatrixRotation3D rotation) Combines provided rotation into this rotation resulting in the multiplication of the internal matrices of both rotations.static voidcombine(MatrixRotation3D rot1, MatrixRotation3D rot2, MatrixRotation3D result) Combines the rotation of instances rot1 and rot1 into provided result instance.voidcombine(Rotation3D rotation) Combines provided rotation into this rotation resulting in the multiplication of the internal matrices of both rotations.combineAndReturnNew(MatrixRotation3D rotation) Combines provided rotation with this rotation and returns the result as a new MatrixRotation3D instance.combineAndReturnNew(Rotation3D rotation) Combines provided rotation with this rotation and returns the result as a new MatrixRotation3D instance.voidfromHomogeneousMatrix(com.irurueta.algebra.Matrix m, double threshold) Sets amount of rotation from provided homogeneous rotation matrix.voidfromInhomogeneousMatrix(com.irurueta.algebra.Matrix m, double threshold) Sets amount of rotation from provided inhomogeneous rotation matrix.voidSets values of this rotation from a 3D matrix rotation.voidSets values of this rotation from a quaternion.doubleReturns alpha euler angle within the range -pi and pi.doubleReturns beta euler angle within the range -pi/2 and pi/2.doubleReturns gamma euler angle within the range -pi and pi.com.irurueta.algebra.MatrixReturns a copy of the internal matrix so that the internal matrix cannot be modified accidentally.doubleReturns pitch angle around y-axis expressed in radians for the 1st possible set of solutions.doubleReturns pitch angle around y-axis expressed in radians for the 2nd possible set of solutions.doubleReturns roll angle around x-axis expressed in radians for the 1st possible set of solutions.private doublegetRollAngle(double pitch) Returns roll angle around x-axis expressed in radians corresponding to provided pitch value.doubleReturns roll angle around x-axis expressed in radians for the 2nd possible set of solutions.doubleReturns rotation amount or angle in radians around the rotation axis associated to this instance.getType()Returns type of this rotation.doubleReturns yaw angle around z axis expressed in radians for the 1st possible set of solutions.private doublegetYawAngle(double pitch) Returns yaw angle around x-axis expressed in radians corresponding to provided pitch value.doubleReturns yaw angle around z axis expressed in radians for the 2nd possible set of solutions.booleanIndicates whether current rotation contains ambiguities (a.k.a. gimbal lock).voidReverses the rotation of this instance.voidinverseRotation(MatrixRotation3D result) Sets into provided MatrixRotation3D instance a rotation inverse to this instance.voidinverseRotation(Rotation3D result) Sets into provided MatrixRotation3D instance a rotation inverse to this instance.Returns a 3D rotation which is inverse to this instance.voidRotates a 3D point using the origin of coordinates as the axis of rotation.voidrotationAxis(double[] axis) Returns rotation axis corresponding to this instance.final voidsetAxisAndRotation(double axisX, double axisY, double axisZ, double theta) Sets the axis and rotation of this instance.final voidsetEulerAngles(double alphaEuler, double betaEuler, double gammaEuler) Sets euler angles of this rotation, expressed in radians.final voidsetInternalMatrix(com.irurueta.algebra.Matrix internalMatrix) Sets the internal matrix of this rotation.final voidsetInternalMatrix(com.irurueta.algebra.Matrix m, double threshold) Sets the internal matrix of this rotation.voidsetRollPitchYaw(double roll, double pitch, double yaw) Sets rotation angles, expressed in radians.voidtoAxisRotation(AxisRotation3D result) Converts this 3D rotation into an axis rotation storing the result into provided instance.voidtoMatrixRotation(MatrixRotation3D result) Converts this 3D rotation into a matrix rotation storing the result into provided instance.voidtoQuaternion(Quaternion result) Converts this 3D rotation into a quaternion storing the result into provided instance.Methods inherited from class com.irurueta.geometry.Rotation3D
create, create, create, create, create, create, equals, equals, equals, fromHomogeneousMatrix, fromInhomogeneousMatrix, fromMatrix, fromMatrix, fromRotation, fromRotation, getRotationAxis, hashCode, isValidRotationMatrix, isValidRotationMatrix, rotate, rotate, rotate, setAxisAndRotation, toAxisRotation, toMatrixRotation, toQuaternion
-
Field Details
-
ROTATION3D_INHOM_MATRIX_ROWS
public static final int ROTATION3D_INHOM_MATRIX_ROWSConstant defining the number of rows on a 3D rotation matrix expressed in inhomogeneous coordinates.- See Also:
-
ROTATION3D_INHOM_MATRIX_COLS
public static final int ROTATION3D_INHOM_MATRIX_COLSConstant defining the number of columns on a 3D rotation matrix expressed in inhomogeneous coordinates.- See Also:
-
ROTATION3D_HOM_MATRIX_ROWS
public static final int ROTATION3D_HOM_MATRIX_ROWSConstant defining the number of rows on a 3D rotation matrix expressed in homogeneous coordinates.- See Also:
-
ROTATION3D_HOM_MATRIX_COLS
public static final int ROTATION3D_HOM_MATRIX_COLSConstant defining the number of columns on a 3D rotation matrix expressed in homogeneous coordinates.- See Also:
-
GIMBAL_THRESHOLD
public static final double GIMBAL_THRESHOLDThreshold to determine that a gimbal locked might have been achieved when trying to find roll, pitch and yaw angles.- See Also:
-
internalMatrix
protected com.irurueta.algebra.Matrix internalMatrixInternal matrix containing rotation using inhomogeneous coordinates. This matrix will be square, 3x3, orthogonal and will have determinant equal to one.
-
-
Constructor Details
-
MatrixRotation3D
public MatrixRotation3D()Empty Constructor. Initializes rotation so that no rotation exists (i.e. internal matrix is the identity). -
MatrixRotation3D
Copy constructor. Copies provided rotation into this instance.- Parameters:
rotation- Instance to be copied.
-
MatrixRotation3D
Copy constructor. Copies and converts provided rotation into this instance.- Parameters:
rotation- Instance to be copied.
-
MatrixRotation3D
Constructor. Creates a 3D rotation using provided matrix. Provided matrix can be expressed in either homogeneous or inhomogeneous coordinates, and it must also be orthogonal and having determinant equal to 1. The threshold to determine whether provided matrix is orthonormal will be DEFAULT_VALID_THRESHOLD.- Parameters:
m- Matrix to create rotation from.- Throws:
InvalidRotationMatrixException- Raised if provided matrix is not valid (its size is wrong, or it is not orthonormal).Rotation3D.isValidRotationMatrix(Matrix).
-
MatrixRotation3D
public MatrixRotation3D(com.irurueta.algebra.Matrix m, double threshold) throws InvalidRotationMatrixException Constructor. Creates a 3D rotation using provided matrix. Provided matrix can be expressed in either homogeneous or inhomogeneous coordinates, and it must also be orthogonal up to provided threshold, and must have determinant equal to 1.- Parameters:
m- Matrix to create rotation from.threshold- Threshold to determine whether matrix is orthonormal.- Throws:
InvalidRotationMatrixException- Raised if provided matrix is not valid (its size is wrong, or it is not orthonormal).IllegalArgumentException- Raised if provided threshold is negative.Rotation3D.isValidRotationMatrix(Matrix).
-
MatrixRotation3D
public MatrixRotation3D(double alphaEuler, double betaEuler, double gammaEuler) Constructor. Creates a 3D rotation using provided Euler angles expressed in radians.- Parameters:
alphaEuler- Alpha Euler angle expressed in radians.betaEuler- Beta Euler angle expressed in radians.gammaEuler- Gamma Euler angle expressed in radians.
-
MatrixRotation3D
public MatrixRotation3D(double[] axis, double theta) Constructor. Creates a 3D reconstruction using provided rotation axis and rotation angle expressed in radians.- Parameters:
axis- Axis of rotation. Axis must be a length-3 array containing the axis vector. For better accuracy axis coordinates should be normalized (norm equal to 1).theta- Angle of rotation respect the axis expressed in radians.- Throws:
IllegalArgumentException- Raised if provided axis does not have length 3.
-
MatrixRotation3D
public MatrixRotation3D(double axisX, double axisY, double axisZ, double theta) Constructor. Creates a 3D reconstruction using provided rotation axis coordinates and rotation angle expressed in radians. Note: for better accuracy axis coordinates should be normalized (norm equal to 1).- Parameters:
axisX- X coordinate of axis.axisY- Y coordinate of axis.axisZ- Z coordinate of axis.theta- Angle of rotation respect the axis expressed in radians.
-
-
Method Details
-
getType
Returns type of this rotation.- Specified by:
getTypein classRotation3D- Returns:
- Type of this rotation.
-
getInternalMatrix
public com.irurueta.algebra.Matrix getInternalMatrix()Returns a copy of the internal matrix so that the internal matrix cannot be modified accidentally. Returned matrix will be 3x3, orthogonal and will have determinant equal to one.- Returns:
- Internal matrix containing rotation of this instance.
-
setInternalMatrix
public final void setInternalMatrix(com.irurueta.algebra.Matrix internalMatrix) throws InvalidRotationMatrixException Sets the internal matrix of this rotation. Provided matrix must be 3x3 and orthonormal (orthogonal with determinant equal to 1).- Parameters:
internalMatrix- Internal matrix to be set.- Throws:
InvalidRotationMatrixException- Raised if provided matrix is not 3x3, or it is not orthonormal.
-
setInternalMatrix
public final void setInternalMatrix(com.irurueta.algebra.Matrix m, double threshold) throws InvalidRotationMatrixException Sets the internal matrix of this rotation. Provided matrix must be 3x3 and orthonormal (orthogonal with determinant equal to 1) up to an error equal to provided threshold.- Parameters:
m- Internal matrix to be set.threshold- Threshold to determine whether matrix is orthonormal or not.- Throws:
InvalidRotationMatrixException- Raised if provided matrix is not 3x3, or it is not orthonormal.IllegalArgumentException- Raised if provided threshold is negative.
-
getAlphaEulerAngle
public double getAlphaEulerAngle()Returns alpha euler angle within the range -pi and pi.- Returns:
- Alpha euler angle expressed in radians.
-
getBetaEulerAngle
public double getBetaEulerAngle()Returns beta euler angle within the range -pi/2 and pi/2.- Returns:
- Beta euler angle expressed in radians.
-
getGammaEulerAngle
public double getGammaEulerAngle()Returns gamma euler angle within the range -pi and pi.- Returns:
- Gamma euler angle expressed in radians.
-
setEulerAngles
public final void setEulerAngles(double alphaEuler, double betaEuler, double gammaEuler) Sets euler angles of this rotation, expressed in radians.- Parameters:
alphaEuler- Alpha euler angle in radians.betaEuler- Beta euler angle in radians.gammaEuler- Gamma euler angle in radians.
-
getRollAngle
public double getRollAngle()Returns roll angle around x-axis expressed in radians for the 1st possible set of solutions. When obtaining roll, pitch and yaw angles from a rotation matrix, there might be two possible sets of solutions (#getRollAngle(), #getPitchAngle(), #getYawAngle()) or (#getRollAngle2(), #getPitchAngle2(), #getYawAngle2()).- Returns:
- roll angle around x-axis.
- See Also:
-
getRollAngle2
public double getRollAngle2()Returns roll angle around x-axis expressed in radians for the 2nd possible set of solutions. When obtaining roll, pitch and yaw angles from a rotation matrix, there might be two possible sets of solutions (#getRollAngle(), #getPitchAngle(), #getYawAngle()) or (#getRollAngle2(), #getPitchAngle2(), #getYawAngle2()).- Returns:
- roll angle around x-axis.
- See Also:
-
getRollAngle
private double getRollAngle(double pitch) Returns roll angle around x-axis expressed in radians corresponding to provided pitch value. This method is used internally.- Parameters:
pitch- pitch angle expressed in radians.- Returns:
- roll angle around x-axis.
-
getPitchAngle
public double getPitchAngle()Returns pitch angle around y-axis expressed in radians for the 1st possible set of solutions. When obtaining roll, pitch and yaw angles from a rotation matrix, there might be two possible sets of solutions (#getRollAngle(), #getPitchAngle(), #getYawAngle()) or (#getRollAngle2(), #getPitchAngle2(), #getYawAngle2()).- Returns:
- pitch angle around y-axis.
- See Also:
-
getPitchAngle2
public double getPitchAngle2()Returns pitch angle around y-axis expressed in radians for the 2nd possible set of solutions. When obtaining roll, pitch and yaw angles from a rotation matrix, there might be two possible sets of solutions (#getRollAngle(), #getPitchAngle(), #getYawAngle()) or (#getRollAngle2(), #getPitchAngle2(), #getYawAngle2()). When a gimbal lock occurs, both pitch angles are equal because only yaw is undefined, but pitch and roll are unique.- Returns:
- pitch angle around y-axis.
- See Also:
-
getYawAngle
public double getYawAngle()Returns yaw angle around z axis expressed in radians for the 1st possible set of solutions. When a gimbal lock occurs (pitch angle is close to +- 90 degrees), then yaw angle is undefined, and can be any value, although this method will return 0.0. When obtaining roll, pitch and yaw angles from a rotation matrix, there might be two possible sets of solutions (#getRollAngle(), #getPitchAngle(), #getYawAngle()) or (#getRollAngle2(), #getPitchAngle2(), #getYawAngle2()).- Returns:
- yaw angle around z axis.
- See Also:
-
getYawAngle2
public double getYawAngle2()Returns yaw angle around z axis expressed in radians for the 2nd possible set of solutions. When a gimbal lock occurs (pitch angle is close to +- 90 degrees), then yaw angle is undefined, and can be any value, although this method will return 0.0. When obtaining roll, pitch and yaw angles from a rotation matrix, there might be two possible sets of solutions (#getRollAngle(), #getPitchAngle(), #getYawAngle()) or (#getRollAngle2(), #getPitchAngle2(), #getYawAngle2()).- Returns:
- yaw angle around z axis.
- See Also:
-
getYawAngle
private double getYawAngle(double pitch) Returns yaw angle around x-axis expressed in radians corresponding to provided pitch value. This method is used internally.- Parameters:
pitch- pitch angle expressed in radians.- Returns:
- yaw angle around x-axis.
-
hasGimbalLock
public boolean hasGimbalLock()Indicates whether current rotation contains ambiguities (a.k.a. gimbal lock). This situation happens when pitch angle is close to +-90 degrees.- Returns:
- true if current rotation contains a gimbal lock, false otherwise.
- See Also:
-
setRollPitchYaw
public void setRollPitchYaw(double roll, double pitch, double yaw) Sets rotation angles, expressed in radians.- Parameters:
roll- roll angle in radians around x-axis.pitch- pitch angle in radians around y-axis.yaw- yaw angle in radians around z-axis.- See Also:
-
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:
setAxisAndRotationin classRotation3D- 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.
-
rotationAxis
Returns rotation axis corresponding to this instance. Result is stored in provided axis array, which must have length 3.- Specified by:
rotationAxisin classRotation3D- Parameters:
axis- Array where axis coordinates will be stored.- Throws:
IllegalArgumentException- Raised if provided array does not have length 3.RotationException- Raised if numerical instabilities happen. Because internal matrix will always be well-defined (orthogonal and determinant equal to 1), this exception will rarely happen.
-
getRotationAngle
Returns rotation amount or angle in radians around the rotation axis associated to this instance.- Specified by:
getRotationAnglein classRotation3D- Returns:
- Rotation angle in radians.
- Throws:
RotationException- Raised if numerical instabilities happen. Because internal matrix will always be well-defined (orthogonal and determinant equal to 1), this exception will rarely happen.
-
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:
inverseRotationAndReturnNewin classRotation3D- Returns:
- Inverse 3D rotation.
-
inverseRotation
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
Sets into provided MatrixRotation3D instance a rotation inverse to this instance. The combination of this rotation with its inverse produces no change.- Specified by:
inverseRotationin classRotation3D- Parameters:
result- Instance where inverse rotation will be set.
-
inverseRotation
public void inverseRotation()Reverses the rotation of this instance.- Specified by:
inverseRotationin classRotation3D
-
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:
asInhomogeneousMatrixin classRotation3D- 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:
asInhomogeneousMatrixin classRotation3D- 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:
asHomogeneousMatrixin classRotation3D- 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:
asHomogeneousMatrixin classRotation3D- 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:
fromInhomogeneousMatrixin classRotation3D- 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:
fromHomogeneousMatrixin classRotation3D- 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
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:
rotatein classRotation3D- Parameters:
inputPoint- Input point to be rotated.resultPoint- Rotated point.
-
combineAndReturnNew
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
Combines provided rotation with this rotation and returns the result as a new MatrixRotation3D instance.- Specified by:
combineAndReturnNewin classRotation3D- 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
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
Combines provided rotation into this rotation resulting in the multiplication of the internal matrices of both rotations.- Specified by:
combinein classRotation3D- Parameters:
rotation- Input rotation to be combined.
-
combine
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
Sets values of this rotation from a 3D matrix rotation.- Overrides:
fromRotationin classRotation3D- Parameters:
rot- 3D matrix rotation to set values from.
-
fromRotation
Sets values of this rotation from a quaternion.- Specified by:
fromRotationin classRotation3D- Parameters:
q- a quaternion to set values from.
-
toMatrixRotation
Converts this 3D rotation into a matrix rotation storing the result into provided instance.- Overrides:
toMatrixRotationin classRotation3D- Parameters:
result- instance where result wil be stored.
-
toAxisRotation
Converts this 3D rotation into an axis rotation storing the result into provided instance.- Overrides:
toAxisRotationin classRotation3D- Parameters:
result- instance where result will be stored.
-
toQuaternion
Converts this 3D rotation into a quaternion storing the result into provided instance.- Overrides:
toQuaternionin classRotation3D- Parameters:
result- instance where result will be stored.
-