Package org.opensourcephysics.numerics
Class Matrix3DTransformation
java.lang.Object
org.opensourcephysics.numerics.Matrix3DTransformation
- All Implemented Interfaces:
Cloneable
,MatrixTransformation
,Transformation
Matrix3DTransformation implements 3D affine transformations using a matrix representation.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected double[][]
protected double[][]
protected double[]
-
Constructor Summary
ConstructorsConstructorDescriptionMatrix3DTransformation
(double[][] matrix) Constructs a 3D transformation using the given matrix. -
Method Summary
Modifier and TypeMethodDescriptionclone()
Provides a copy of this transformation.static Matrix3DTransformation
createAlignmentTransformation
(double[] v1, double[] v2) Instantiates a rotation that aligns the first vector with the second vector.double[]
direct
(double[] point) Transforms the given point+.double[][]
direct
(double[][] mat) Transforms the given matrix into the transformation's coordinate system.final double[]
getFlatMatrix
(double[] mat) Gets the direct homogeneous affine transformation flattened into a 1-d array.static XML.ObjectLoader
double[]
final double[]
getTransposedFlatMatrix
(double[] mat) Gets the direct homogeneous affine transformation flattened into a 1-d array, ordered left to right, top to bottom If the mat parameter is null a double[16] array is created; otherwise the given array is used.double[]
inverse
(double[] point) Transforms the given point using the inverse transformation (if it exists).double[][]
inverse
(double[][] mat) Transforms the given matrix from the transformation's coordinate system.final void
multiply
(double[][] mat) Multiplies this rotation matrix by the given matrix from the right.final void
multiply
(Matrix3DTransformation trans) Multiplies (concatenates) this transformation matrix with the given transformation.static Matrix3DTransformation
Quaternion
(double[] quaternion) Creates an transformation representing a rotation about the origin by the given quaternion.static Matrix3DTransformation
Quaternion
(double q0, double q1, double q2, double q3) Creates an AffineMatrix representing a rotation about the origin by the given quaternion components.static Matrix3DTransformation
rotation
(double theta, double[] axis) Creates a 3D transforamtion representing a rotation about the origin by the given angle around the given axis.static Matrix3DTransformation
rotationX
(double theta) Creates a 3D transforamtion representing a rotation about the x axis by the given angle.static Matrix3DTransformation
rotationY
(double theta) Creates a 3D transforamtion representing a rotation about the y axis by the given angle.static Matrix3DTransformation
rotationZ
(double theta) Creates a 3D transforamtion representing a rotation about the z axis by the given angle.boolean
setMatrix
(double[] newMatrix) Sets the matrix array of the rotationboolean
setMatrix
(double[][] newMatrix) Sets the double[][] matrix array of the rotationdouble[]
setOrigin
(double[] origin) Sets the origin for this rotation.void
setOrigin
(double ox, double oy, double oz) Sets the origin for this rotation.final double[]
toQuaternion
(double[] q)
-
Field Details
-
origin
protected double[] origin -
matrix
protected double[][] matrix -
inverseMatrix
protected double[][] inverseMatrix
-
-
Constructor Details
-
Matrix3DTransformation
public Matrix3DTransformation(double[][] matrix) Constructs a 3D transformation using the given matrix. Affine transformations can be applied to 3D coordinates. A 3 by 3 matrix sets the rotation and shear. A null matrix sets the transformation to the identity transformation.- Parameters:
matrix
- double[][]
-
-
Method Details
-
rotationX
Creates a 3D transforamtion representing a rotation about the x axis by the given angle.- Parameters:
theta
- double- Returns:
- Affine3DTransformation
-
rotationY
Creates a 3D transforamtion representing a rotation about the y axis by the given angle.- Parameters:
theta
- double- Returns:
- Affine3DTransformation
-
rotationZ
Creates a 3D transforamtion representing a rotation about the z axis by the given angle.- Parameters:
theta
- double- Returns:
- Affine3DTransformation
-
rotation
Creates a 3D transforamtion representing a rotation about the origin by the given angle around the given axis.- Parameters:
theta
- doubleaxis
- double[]- Returns:
- Affine3DTransformation
-
Quaternion
Creates an transformation representing a rotation about the origin by the given quaternion.- Parameters:
quaternion
- double[]- Returns:
- Affine3DTransformation
-
Quaternion
Creates an AffineMatrix representing a rotation about the origin by the given quaternion components.- Parameters:
q0
-q1
-q2
-q3
-- Returns:
- Affine3DTransformation
-
setMatrix
public boolean setMatrix(double[][] newMatrix) Sets the double[][] matrix array of the rotation- Parameters:
newMatrix
-
-
setMatrix
public boolean setMatrix(double[] newMatrix) Sets the matrix array of the rotation- Parameters:
matrix
- a double[9] array with the matrix components in this order {m[0][0],m[0][1],m[0][2],m[1][0],...}
-
clone
Provides a copy of this transformation.- Specified by:
clone
in interfaceTransformation
- Overrides:
clone
in classObject
-
getFlatMatrix
public final double[] getFlatMatrix(double[] mat) Gets the direct homogeneous affine transformation flattened into a 1-d array. If the mat parameter is null a double[16] array is created; otherwise the given array is used.- Specified by:
getFlatMatrix
in interfaceMatrixTransformation
- Parameters:
mat
- double[] optional matrix- Returns:
- double[] the matrix
-
getTransposedFlatMatrix
public final double[] getTransposedFlatMatrix(double[] mat) Gets the direct homogeneous affine transformation flattened into a 1-d array, ordered left to right, top to bottom If the mat parameter is null a double[16] array is created; otherwise the given array is used.- Parameters:
mat
- double[] optional matrix- Returns:
- double[] the matrix
-
toQuaternion
public final double[] toQuaternion(double[] q) -
createAlignmentTransformation
Instantiates a rotation that aligns the first vector with the second vector.- Parameters:
v1
- double[]v2
- double[]- Returns:
- Quaternion
-
setOrigin
public void setOrigin(double ox, double oy, double oz) Sets the origin for this rotation.- Parameters:
ox
- doubleoy
- doubleoz
- double
-
multiply
Multiplies (concatenates) this transformation matrix with the given transformation.- Parameters:
trans
- Matrix3DTransformation
-
multiply
public final void multiply(double[][] mat) Multiplies this rotation matrix by the given matrix from the right.- Parameters:
mat
- double[][]
-
setOrigin
public double[] setOrigin(double[] origin) Sets the origin for this rotation.- Parameters:
origin
- double[] the new origin- Returns:
- double[]
-
direct
public double[] direct(double[] point) Transforms the given point+.- Specified by:
direct
in interfaceTransformation
- Parameters:
point
- the coordinates to be transformed- Returns:
- double[] the transformed vector (i.e. point)
-
direct
public double[][] direct(double[][] mat) Transforms the given matrix into the transformation's coordinate system.- Parameters:
matrix
- to be transformed
-
inverse
Transforms the given point using the inverse transformation (if it exists). If the transformation is not invertible, then a call to this method must throw a UnsupportedOperationException exception.- Specified by:
inverse
in interfaceTransformation
- Parameters:
point
- the coordinates to be transformed- Returns:
- double[] the transformed vector (i.e. point)
- Throws:
UnsupportedOperationException
- If the transformation is not invertible
-
inverse
public double[][] inverse(double[][] mat) Transforms the given matrix from the transformation's coordinate system.- Parameters:
matrix
- to be transformed
-
getOrigin
public double[] getOrigin() -
getLoader
-