Class AffineTransform


class AffineTransform
This is a class that specifies special matrices that are affine transformations of homogeneous coordinates and allows them to be applied to point2D and point3D objectss. This class is primarily used internally by the point2D and point3D classes, but can also be called as such, for example:
var T = new AffineTransform(3).rotationX(Math.PI);
var p3D = T.applyTo(new mathnetics.point3D(1,1,1));
The transformation methods return the current AffineTransform object, allowing compound transformation. Compound transformations are handled in reverse order. For example:
var T = new AffineTransform(3).rotationX(Math.PI).translate3D(1,1,1);
var p3D = T.applyTo(new mathnetics.point3D(1,1,1));

represents the following operation:
p3D = (translate3D(1,1,1) x rotationX(Math.PI)) x (1,1,1,1);
p3D =
([1 0 0 1] [1 0 0 0] ) [1]
([0 1 0 1] [0 -1 0 0]) [1]
([0 0 1 1] [0 0 -1 0]) [1]
([0 0 0 1] [0 0 0 1] ) [1]
(NOTE: [1 1 1 1] is the column matrix representation of the new point3D(1,1,1) object)

Note that the transformation methods update the current AffineTransform object (allowing compound transformations) while the invert() method creates a new AffineTransform object with the opposite transformation as its matrix.
Defined in AffineTransform.js

Variable Summary
private int dim
The dimension of the transformation (1 less than dimension of matrix).
private Matrix matrix
The transformation matrix that will be created when specific methods are called.

Constructor Summary
AffineTransform (int dim)
Construct a new AffineTransform object, which contains a dimension, a transformation matrix (set by instance methods), and the applyTo method.

Function Summary
public Object applyTo (mathnetics.point2D point)
public Object applyTo (mathnetics.point3D point)
Applies the transformation to a mathnetics.point2D or mathnetics.point3D object.
Inverts an Affine Transformation.
public boolean invertible()
Tests to see if an Affine Transformation is invertible.
public AffineTransform newCoordinates (Number theta, Number phi)
Transforms a point in Euler coordinates to a new coordinate system, defined by a normal vector from the origin.
public AffineTransform rotate2D (Number theta)
Rotates a point (x,y,1) about the angle theta in the xy-plane.
public AffineTransform rotation (Number theta, [mathnetics.point3D axis])
public AffineTransform rotation (Number theta, [Vector axis])
public AffineTransform rotation (Number theta, [Line axis])
public AffineTransform rotation (Number theta, [Number[] axis])
Creates a rotation matrix about an arbitrary axis.
public AffineTransform rotationX (Number phi)
Rotates a point (x,y,z,1) through an angle phi about the x-axis.
public AffineTransform rotationY (Number phi)
Rotates a point (x,y,z,1) through an angle theta about the y-axis.
public AffineTransform rotationZ (Number phi)
Rotates a point (x,y,z,1) through an angle psi about the z-axis.
public String toString()
Returns a string representation of the Affine Transformation matrix.
public AffineTransform translate2D (Number tx, Number ty, Number tz)
Creates a 2D translation matrix (3x3).
public AffineTransform translate3D (Number tx, Number ty, Number tz)
Creates a 3D translation matrix (4x4).

Variable Details

variable private int dim

The dimension of the transformation (1 less than dimension of matrix).

variable private Matrix matrix

The transformation matrix that will be created when specific methods are called.

Constructor Details

constructor AffineTransform

AffineTransform(int dim)
Construct a new AffineTransform object, which contains a dimension, a transformation matrix (set by instance methods), and the applyTo method.
Parameters:
dim - the dimension (2 or 3) of the Affine Transformation.

Function Details

function applyTo

public Object applyTo(mathnetics.point2D point)
public Object applyTo(mathnetics.point3D point)
Applies the transformation to a mathnetics.point2D or mathnetics.point3D object.
Parameters:
2D
point
3D
point
Returns:
a point2D or point3D object, depending on the dimension called

function invert

public AffineTransform invert()
Inverts an Affine Transformation. This function IS different from inverting a Matrix. See: http://en.wikipedia.org/wiki/Affine_transformation#properties_of_affine_transformations
Returns:
a new AffineTransform object that does the inverse transformation of the original

function invertible

public boolean invertible()
Tests to see if an Affine Transformation is invertible.
Returns:
true iff invertible, false otherwise

function newCoordinates

public AffineTransform newCoordinates(Number theta, Number phi)
Transforms a point in Euler coordinates to a new coordinate system, defined by a normal vector from the origin. The new coordinate system is defined by two angles: theta (from positive x-axis in XY-plane) and phi (from positive z-axis). These angles define the direction from the origin of the new x-axis. The y and z axes are defined by the plane formed with this point as a normal that goes through the origin. This model is used because it does not rotate the object. The matrix constructed is:
[cos(theta)*sin(phi), sin(theta)*sin(phi), cos(phi), 0]
[-sin(theta), cos(theta), 0, 0]
[-cos(theta)*cos(phi), -sin(theta)*cos(phi), sin(phi), 0]
[0, 0, 0, 1]
Parameters:
theta - the degree (in radians) on the XY-plane to the normal vector
phi - the degree in radians from the positive z axis to the normal vector
Returns:
this AffineTransform object, with updated matrix

function rotate2D

public AffineTransform rotate2D(Number theta)
Rotates a point (x,y,1) about the angle theta in the xy-plane. Note that this is the same as Math.rotationZ in one less dimension.
Parameters:
theta - the degrees (in radians) to rotate the point by
Returns:
this AffineTransform object, with updated matrix
See also:

function rotation

public AffineTransform rotation(Number theta, [mathnetics.point3D axis])
public AffineTransform rotation(Number theta, [Vector axis])
public AffineTransform rotation(Number theta, [Line axis])
public AffineTransform rotation(Number theta, [Number[] axis])
Creates a rotation matrix about an arbitrary axis. If no axis supplied, assume 2D rotation of theta in XY-plane
Parameters:
Point
theta - the number of degrees (in radians) to rotate
[axis] - the axis (point3D) about which to rotate
Vector
theta - the number of degrees (in radians) to rotate
[axis] - the axis (3-D Vector) about which to rotate
Line
theta - the number of degrees (in radians) to rotate
[axis] - the axis (Line) about which to rotate
Array
theta - the number of degrees (in radians) to rotate
[axis] - the axis (length 3 Array) about which to rotate
Returns:
{AffineTransform} this AffineTransform object

function rotationX

public AffineTransform rotationX(Number phi)
Rotates a point (x,y,z,1) through an angle phi about the x-axis.
Parameters:
phi - the degrees (in radians) to rotate the point by
Returns:
this AffineTransform object, with updated matrix

function rotationY

public AffineTransform rotationY(Number phi)
Rotates a point (x,y,z,1) through an angle theta about the y-axis.
Parameters:
phi - the degrees (in radians) to rotate the point by
Returns:
this AffineTransform object, with updated matrix

function rotationZ

public AffineTransform rotationZ(Number phi)
Rotates a point (x,y,z,1) through an angle psi about the z-axis.
Parameters:
phi - the degrees (in radians) to rotate the point by
Returns:
this AffineTransform object, with updated matrix

function toString

public String toString()
Returns a string representation of the Affine Transformation matrix.
Returns:
the string representation of this transformation's matrix
See also:

function translate2D

public AffineTransform translate2D(Number tx, Number ty, Number tz)
Creates a 2D translation matrix (3x3). To be applied to a 2D point (x,y,1) as such: (x',y',1) = translate2D*(x,y,1)
Parameters:
tx - the x-coordinate translation
ty - the y-coordinate translation
tz - the z-coordinate translation
Returns:
this AffineTransform object, with updated matrix

function translate3D

public AffineTransform translate3D(Number tx, Number ty, Number tz)
Creates a 3D translation matrix (4x4). To be applied to a 3D point (x,y,z,1) as such: (x',y',z',1) = translate3D*(x,y,z,1)
Parameters:
tx - the x-coordinate translation
ty - the y-coordinate translation
tz - the z-coordinate translation
Returns:
this AffineTransform object, with the matrix updated to the translate3D matrix