public class CoordinateTransformer3DFloat
extends java.lang.Object
VoxelArray
, because it
intelligently composes a single tranformation matrix and performs only
one transformation which can be reversed. (VoxelArray.transform actually
computes and performs the *inverse* transform of the transform you give
it, eliminating holes in the target VoxelArray space.)
You will usually construct one of these transformations by using one of
the make... methods.
To compose transformations, you can construct them individually and then
compose them using the multiply method. NOTE THAT YOU USUALLY NEED TO
MULTIPLY THEM IN THE REVERSE ORDER OF WHICH YOU CONCEPTUALLY APPLY THEM.
No books tell you this explicitly enough.
For derivations of some of the rotation matrices, see:
Glenn Murray: Rotation Matrices and Formulas
For data about finding the inverse, see:
See How to
find the inverse matrix of a 4x4 matrix.Modifier and Type | Field and Description |
---|---|
static CoordinateTransformer3DFloat |
IDENTITY
The identity matrix.
|
private float |
m11
Coordinates are split out into individual variables to make them more
readable and to follow old matrix indexing conventions.
|
private float |
m12 |
private float |
m13 |
private float |
m14 |
private float |
m21 |
private float |
m22 |
private float |
m23 |
private float |
m24 |
private float |
m31 |
private float |
m32 |
private float |
m33 |
private float |
m34 |
private static float |
TOLERANCE
How close a float must be to a float to be "equal".
|
Modifier | Constructor and Description |
---|---|
private |
CoordinateTransformer3DFloat()
The constructor is private.
|
|
CoordinateTransformer3DFloat(float m11,
float m12,
float m13,
float m14,
float m21,
float m22,
float m23,
float m24,
float m31,
float m32,
float m33,
float m34)
Make an arbitrary transformation matrix.
|
Modifier and Type | Method and Description |
---|---|
float |
determinant()
Returns the determinant of this matrix.
|
CoordinateTransformer3DFloat |
inverse()
Returns the inverse of this matrix.
|
static CoordinateTransformer3DFloat |
makeRotate(float a,
float b,
float c,
float uUn,
float vUn,
float wUn,
double theta)
Build a rotation matrix for rotations about the line through the point
(a, b, c) parallel to the vector [u, v, w] by the angle theta.
|
static CoordinateTransformer3DFloat |
makeRotate(Point3DFloat point,
Point3DFloat vec,
double theta)
Build a rotation matrix for rotations about the line through the point
point parallel to the vector vec
by the angle theta. |
static CoordinateTransformer3DFloat |
makeRotateX(float a,
float b,
float c,
double theta)
Build a rotation matrix for rotations about the line through the point
(a, b, c) parallel to the x-axis by the angle theta.
|
static CoordinateTransformer3DFloat |
makeRotateXYZ(float a,
float b,
float c,
double thetaX,
double thetaY,
double thetaZ)
Build a rotation matrix for three rotations around the point (a, b, c)
by performing 3 successive rotations about the x, y, and z axes in that
order.
|
static CoordinateTransformer3DFloat |
makeRotateY(float a,
float b,
float c,
double theta)
Build a rotation matrix for rotations about the line through the point
(a, b, c) parallel to the y-axis by the angle theta.
|
static CoordinateTransformer3DFloat |
makeRotateZ(float a,
float b,
float c,
double theta)
Build a rotation matrix for rotations about the line through the point
(a, b, c) parallel to the z-axis by the angle theta.
|
static CoordinateTransformer3DFloat |
makeScale(float sx,
float sy,
float sz)
Build a scaling matrix for scalings along the major axes.
|
static CoordinateTransformer3DFloat |
makeTranslate(float x,
float y,
float z)
Build a translation matrix for translations along the major axes.
|
static CoordinateTransformer3DFloat |
makeVerticalToLine(float x1,
float y1,
float z1,
float x2,
float y2,
float z2,
double thetaZ)
Makes a transform that will map an object rendered vertically (along
the Z axis, probably based at the origin) to lay along a line from p1
(which is mapped from the origin) to p2.
|
static CoordinateTransformer3DFloat |
makeVerticalToPlane(float x,
float y,
float z,
float u,
float v,
float w,
double thetaZ)
Makes a transform that will map an object rendered vertically (along
the Z axis, probably based at the origin) to lay along a plane given a
point on the plane (specified by (x,y,z)) and a normal to the plane
(specified by (u,v,w)).
|
CoordinateTransformer3DFloat |
multiply(CoordinateTransformer3DFloat b)
Multiplies this CoordinateTransformer3DFloat with another and returns
the new transformation matrix.
|
CoordinateTransformer3DFloat |
round()
Rounds the elements of a matrix to the nearest integer values.
|
private static double |
softSignum(double x)
Returns a "soft" signum that is either -1 or 1 and never 0 because 0
wrecks some of these algorithms.
|
frink.expr.ListExpression |
toExpression()
Converts this matrix to a 2-dimensional ListExpression.
|
java.lang.String |
toString()
Formats the transformation matrix as a string.
|
Point3DFloat |
transform(float x,
float y,
float z,
Point3DFloat out)
Transform the coordinate (x, y, z) by this matrix.
|
Point3DFloat |
transform(Point3DFloat in,
Point3DFloat out)
Transform the coordinate (x, y, z) by this matrix.
|
private static final float TOLERANCE
private float m11
private float m12
private float m13
private float m14
private float m21
private float m22
private float m23
private float m24
private float m31
private float m32
private float m33
private float m34
public static final CoordinateTransformer3DFloat IDENTITY
private CoordinateTransformer3DFloat()
public CoordinateTransformer3DFloat(float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24, float m31, float m32, float m33, float m34)
public static CoordinateTransformer3DFloat makeRotate(float a, float b, float c, float uUn, float vUn, float wUn, double theta) throws frink.expr.InvalidArgumentException
a
- x-coordinate of a point on the line of rotation.b
- y-coordinate of a point on the line of rotation.c
- z-coordinate of a point on the line of rotation.uUn
- x-coordinate of the line's direction vector (unnormalized).vUn
- y-coordinate of the line's direction vector (unnormalized).wUn
- z-coordinate of the line's direction vector (unnormalized).theta
- The angle of rotation, in radians. Looking from a positive
axis toward the origin, a positive angle gives a counterclockwise
rotation.frink.expr.InvalidArgumentException
public static CoordinateTransformer3DFloat makeRotate(Point3DFloat point, Point3DFloat vec, double theta) throws frink.expr.InvalidArgumentException
point
parallel to the vector vec
by the angle theta.point
- a point on the line of rotation.vec
- a vector (which can be unnormalized.)theta
- The angle of rotation, in radians. Looking from a positive
axis toward the origin, a positive angle gives a counterclockwise
rotation.frink.expr.InvalidArgumentException
public static CoordinateTransformer3DFloat makeRotateX(float a, float b, float c, double theta) throws frink.expr.InvalidArgumentException
a
- x-coordinate of a point on the line of rotation.b
- y-coordinate of a point on the line of rotation.c
- z-coordinate of a point on the line of rotation.theta
- The angle of rotation, in radians. Looking from a positive
axis toward the origin, a positive angle gives a counterclockwise
rotation.frink.expr.InvalidArgumentException
public static CoordinateTransformer3DFloat makeRotateY(float a, float b, float c, double theta) throws frink.expr.InvalidArgumentException
a
- x-coordinate of a point on the line of rotation.b
- y-coordinate of a point on the line of rotation.c
- z-coordinate of a point on the line of rotation.theta
- The angle of rotation, in radians. Looking from a positive
axis toward the origin, a positive angle gives a counterclockwise
rotation.frink.expr.InvalidArgumentException
public static CoordinateTransformer3DFloat makeRotateZ(float a, float b, float c, double theta) throws frink.expr.InvalidArgumentException
a
- x-coordinate of a point on the line of rotation.b
- y-coordinate of a point on the line of rotation.c
- z-coordinate of a point on the line of rotation.theta
- The angle of rotation, in radians. Looking from a positive
axis toward the origin, a positive angle gives a counterclockwise
rotation.frink.expr.InvalidArgumentException
public static CoordinateTransformer3DFloat makeRotateXYZ(float a, float b, float c, double thetaX, double thetaY, double thetaZ) throws frink.expr.InvalidArgumentException
a
- x-coordinate of a point on the line of rotation.b
- y-coordinate of a point on the line of rotation.c
- z-coordinate of a point on the line of rotation.thetaX
- The angle of rotation around a line parallel to the X
axis, in radians. Looking from a positive axis toward the origin, a
positive angle gives a counterclockwise rotation.thetaY
- The angle of rotation around a line parallel to the Y
axis, in radians. Looking from a positive axis toward the origin, a
positive angle gives a counterclockwise rotation.thetaZ
- The angle of rotation around a line parallel to the Z
axis, in radians. Looking from a positive axis toward the origin, a
positive angle gives a counterclockwise rotation.frink.expr.InvalidArgumentException
public static CoordinateTransformer3DFloat makeTranslate(float x, float y, float z)
x
- x-coordinate to add to the translation.y
- y-coordinate to add to the translation.z
- z-coordinate to add to the translation.public static CoordinateTransformer3DFloat makeScale(float sx, float sy, float sz)
sx
- scale in the x directionsy
- scale in the y directionsz
- scale in the z directionpublic static CoordinateTransformer3DFloat makeVerticalToLine(float x1, float y1, float z1, float x2, float y2, float z2, double thetaZ) throws frink.expr.InvalidArgumentException
frink.expr.InvalidArgumentException
public static CoordinateTransformer3DFloat makeVerticalToPlane(float x, float y, float z, float u, float v, float w, double thetaZ) throws frink.expr.InvalidArgumentException
frink.expr.InvalidArgumentException
private static double softSignum(double x)
public Point3DFloat transform(float x, float y, float z, Point3DFloat out)
x
- The point's x-coordinate.y
- The point's y-coordinate.z
- The point's z-coordinate.out
- An (optional) pre-allocated Point3DFloat that will contain
the result. If this is null, a new Point3DFloat will be allocated.public Point3DFloat transform(Point3DFloat in, Point3DFloat out)
in
- The point to be transformed.out
- An (optional) pre-allocated Point3DFloat that will contain
the result. If this is null, a new Point3DFloat will be allocated.public CoordinateTransformer3DFloat multiply(CoordinateTransformer3DFloat b)
public float determinant()
public CoordinateTransformer3DFloat inverse()
public CoordinateTransformer3DFloat round()
public frink.expr.ListExpression toExpression()
public java.lang.String toString()
toString
in class java.lang.Object