org.opensourcephysics.numerics
Class Matrix3DTransformation

java.lang.Object
  extended by org.opensourcephysics.numerics.Matrix3DTransformation
All Implemented Interfaces:
java.lang.Cloneable, MatrixTransformation, Transformation
Direct Known Subclasses:
AxisRotation, Matrix3DTransformation

public class Matrix3DTransformation
extends java.lang.Object
implements MatrixTransformation

Matrix3DTransformation implements 3D affine transformations using a matrix representation.


Constructor Summary
Matrix3DTransformation(double[][] matrix)
          Constructs a 3D transformation using the given matrix.
 
Method Summary
 java.lang.Object clone()
          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.
 double[] getFlatMatrix(double[] mat)
          Gets the direct homogeneous affine transformation flattened into a 1-d array.
static XML.ObjectLoader getLoader()
           
 double[] getOrigin()
           
 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.
 void multiply(double[][] mat)
          Multiplies this rotation matrix by the given matrix from the right.
 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 rotation
 boolean setMatrix(double[][] newMatrix)
          Sets the double[][] matrix array of the rotation
 double[] setOrigin(double[] origin)
          Sets the origin for this rotation.
 void setOrigin(double ox, double oy, double oz)
          Sets the origin for this rotation.
 double[] toQuaternion(double[] q)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

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 Detail

rotationX

public static Matrix3DTransformation rotationX(double theta)
Creates a 3D transforamtion representing a rotation about the x axis by the given angle.

Parameters:
theta - double
Returns:
Affine3DTransformation

rotationY

public static Matrix3DTransformation rotationY(double theta)
Creates a 3D transforamtion representing a rotation about the y axis by the given angle.

Parameters:
theta - double
Returns:
Affine3DTransformation

rotationZ

public static Matrix3DTransformation rotationZ(double theta)
Creates a 3D transforamtion representing a rotation about the z axis by the given angle.

Parameters:
theta - double
Returns:
Affine3DTransformation

rotation

public 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.

Parameters:
theta - double
axis - double[]
Returns:
Affine3DTransformation

Quaternion

public static Matrix3DTransformation Quaternion(double[] quaternion)
Creates an transformation representing a rotation about the origin by the given quaternion.

Parameters:
quaternion - double[]
Returns:
Affine3DTransformation

Quaternion

public 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.

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

public java.lang.Object clone()
Provides a copy of this transformation.

Specified by:
clone in interface Transformation
Overrides:
clone in class java.lang.Object

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 interface MatrixTransformation
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

public static Matrix3DTransformation createAlignmentTransformation(double[] v1,
                                                                   double[] v2)
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 - double
oy - double
oz - double

multiply

public final void multiply(Matrix3DTransformation trans)
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 interface Transformation
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

public double[] inverse(double[] point)
                 throws java.lang.UnsupportedOperationException
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 interface Transformation
Parameters:
point - the coordinates to be transformed
Returns:
double[] the transformed vector (i.e. point)
Throws:
java.lang.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

public static XML.ObjectLoader getLoader()