smithers.java3d
Class Transformation

java.lang.Object
  extended by smithers.java3d.Transformation

public class Transformation
extends java.lang.Object

Represents a transformation between two real vector spaces. For example, from 3-dimensional space to 2-dimensional space. This class is general enough to include all affine linear transformations, as well as perspective transformations.


Constructor Summary
Transformation(int n, int m)
          Constructs a new matrix representing an identity/projection/inclusion.
 
Method Summary
 float[] apply(float[] vector)
          Apply this transformation to a vector.
 float[][] apply(float[][] vector, float[][] result)
          Apply this transformation to an array of vectors.
static Transformation composition(Transformation mat1, Transformation mat2)
          Computes the transformation obtained by performing the transformation mat1 after the transformation mat2.
 float getFactor(float[] vector)
           
 float[][] invert(float[] vector)
           
static Transformation perspective(int m)
          Creates a perspective transformation.
 void postCompose(Transformation other)
          Appends the given operation onto this one.
 void preCompose(Transformation other)
          Prepends the given operation onto this one.
static Transformation rotation(int n, int axis1, int axis2, float theta)
          Creates a rotation transformation.
static Transformation rotation2D(float theta)
           
static Transformation rotation3DFromIntrinsicXYZ(float theta1, float theta2, float theta3)
           
static Transformation rotation3DFromIntrinsicZXZ(float theta1, float theta2, float theta3)
           
static Transformation scale(int n, float scale)
           
static Transformation translation(float... vector)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Transformation

public Transformation(int n,
                      int m)
Constructs a new matrix representing an identity/projection/inclusion. If n==m this is an identity transformation, if n<m this is a projection onto the first n coordinates and if n>m then this is an inclusion of the subspace specified by the first m coordinates.

Parameters:
n - the dimension of the space to map to
m - the dimension of the space to map from
Method Detail

perspective

public static Transformation perspective(int m)
Creates a perspective transformation. The returned transformation maps from m dimensions down to m-1. The transformation is to project onto the first m-1 coordinates and then divide by the final coordinate.

Parameters:
m - the dimension to map from
Returns:
the perspective transformation

translation

public static Transformation translation(float... vector)

scale

public static Transformation scale(int n,
                                   float scale)

rotation

public static Transformation rotation(int n,
                                      int axis1,
                                      int axis2,
                                      float theta)
Creates a rotation transformation. The returned transformation is a rotation of n-dimensional space which rotates the axis indexed by axis1 towards the axis indexed by axis2 by an angle of theta radians.

Parameters:
n - the number of dimensions
axis1 - the axis to rotate from
axis2 - the axis to rotate towards
theta - the angle to rotate by
Returns:
the rotation

rotation2D

public static Transformation rotation2D(float theta)

rotation3DFromIntrinsicZXZ

public static Transformation rotation3DFromIntrinsicZXZ(float theta1,
                                                        float theta2,
                                                        float theta3)

rotation3DFromIntrinsicXYZ

public static Transformation rotation3DFromIntrinsicXYZ(float theta1,
                                                        float theta2,
                                                        float theta3)

composition

public static Transformation composition(Transformation mat1,
                                         Transformation mat2)
Computes the transformation obtained by performing the transformation mat1 after the transformation mat2. This is in keeping with the order in the mathematical meaning of the composition mat1 ˆ mat2. mat1 must map from the same number of dimensiona that mat2 maps to.

Parameters:
mat1 - the operation to apply second
mat2 - the operation to apply first
Returns:
the composite transformation

preCompose

public void preCompose(Transformation other)
Prepends the given operation onto this one. The given operation must be square of the same dimension that this one maps from.

Parameters:
other - the transformation to be prepended

postCompose

public void postCompose(Transformation other)
Appends the given operation onto this one. The given operation must be square of the same dimension that this one maps to.

Parameters:
other - the transformation to be appended

getFactor

public float getFactor(float[] vector)

apply

public float[] apply(float[] vector)
Apply this transformation to a vector. The length of the vector must be the same as the dimension this transformation maps from.

Parameters:
vector - the vector to transform
Returns:
the transformed vector

apply

public float[][] apply(float[][] vector,
                       float[][] result)
Apply this transformation to an array of vectors. Each element of vector must be the same as the dimension this transformation maps from. If result is not null, the result vectors will be stored in it. In this case it must have the same length as vector, and each element must have the length of the dimension that this transformation maps to.

Parameters:
vector - the vectors to transform
result - if not null, the result will be stored here
Returns:
the transformed vectors

invert

public float[][] invert(float[] vector)