org.opensourcephysics.numerics
Class Matrix3DTransformation

java.lang.Object
  extended byorg.opensourcephysics.numerics.Matrix3DTransformation
All Implemented Interfaces:
java.lang.Cloneable, MatrixTransformation, Transformation

public class Matrix3DTransformation
extends java.lang.Object
implements MatrixTransformation

Matrix3DTransformation implements 3D affine transformations using a matrix representation.


Nested Class Summary
protected static class Matrix3DTransformation.Affine3DTransformationLoader
           
 
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[] getFlatMatrix(double[] mat)
          Gets the direct homogeneous affine transformation flattened into a 1-d arrray.
static XML.ObjectLoader getLoader()
           
 double[] getSquareMatrix(double[] mat)
          Gets the direct homogeneous affine transformation flattened into a 1-d arrray, 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).
 void multiply(double[][] mat)
          Multiplies this rotation matrix by the given matrix.
 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.
 double[] setOrigin(double[] origin)
          Sets the origin for this rotation.
 void setOrigin(double ox, double oy, double oz)
          Sets the origin for this rotation.
 
Methods inherited from class java.lang.Object
equals, finalize, 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

clone

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

Specified by:
clone in interface Transformation

getFlatMatrix

public final double[] getFlatMatrix(double[] mat)
Gets the direct homogeneous affine transformation flattened into a 1-d arrray. 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

getSquareMatrix

public final double[] getSquareMatrix(double[] mat)
Gets the direct homogeneous affine transformation flattened into a 1-d arrray, 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

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.

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. Convertes the point to homogeneous coordinates if the size of the point array is less than

Specified by:
direct in interface Transformation
Parameters:
point - the coordinates to be transformed
Returns:
double[] the transformed vector (i.e. point)

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

getLoader

public static XML.ObjectLoader getLoader()