Class Matrix
- java.lang.Object
-
- renderer.scene.Matrix
-
public final class Matrix extends Object
AMatrixobject has fourVectorobjects.The four
Vectorobjects represent the four column vectors of the 4-by-4 matrix (as in a Linear Algebra course).In computer graphics, the points and vectors of 3-dimensional space are represented using 4-dimensional homogeneous coordinates. So each transformation of 3-dimensional space is represented by a 4-by-4 (homogeneous) matrix.
A 4-by-4 matrix represents a transformation of 3-dimensional space. The most common transformations are translation, rotation, and scaling. A 4-by-4 matrix can also represent a projection transformation.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static MatrixbuildFromColumns(Vector c1, Vector c2, Vector c3, Vector c4)This is a static facory method.static MatrixbuildFromRows(Vector r1, Vector r2, Vector r3, Vector r4)This is a static facory method.Matrixeulerize()Assuming that thisMatrixrepresents a 3D rotation, return the rotation matrix formed by multiplying this matrix's three Euler angle rotations in the orderR_z * R_y * R_x.static Matrixidentity()This is a static facory method.double[]rot2euler()Assuming that the 3-by-3 "rotation part" of this 4-by-4Matrixrepresents a pure rotation, return the rotation's three Euler angles, in radians, in the order[x, y, z]for rotations in the orderR_z * R_y * R_x.static Matrixrotate(double theta, double x, double y, double z)This is a static facory method.static MatrixrotateX(double theta)This is a static facory method.static MatrixrotateY(double theta)This is a static facory method.static MatrixrotateZ(double theta)This is a static facory method.static Matrixscale(double d)This is a static facory method.static Matrixscale(double x, double y, double z)This is a static facory method.Matrixtimes(double s)A scalar times thisMatrixreturns a newMatrix.Matrixtimes(Matrix m)ThisMatrixtimesMatrixmreturns a newMatrix.Vectortimes(Vector v)Vertextimes(Vertex v)StringtoString()For debugging.static Matrixtranslate(double x, double y, double z)This is a static facory method.
-
-
-
Method Detail
-
buildFromColumns
public static Matrix buildFromColumns(Vector c1, Vector c2, Vector c3, Vector c4)
This is a static facory method.Construct an arbitrary 4-by-4
Matrixusing the given columnVectors.
-
buildFromRows
public static Matrix buildFromRows(Vector r1, Vector r2, Vector r3, Vector r4)
This is a static facory method.Construct an arbitrary 4-by-4
Matrixusing the given rowVectors.
-
identity
public static Matrix identity()
This is a static facory method.Construct an identity
Matrix.- Returns:
- a new
Matrixobject containing an identityMatrix
-
translate
public static Matrix translate(double x, double y, double z)
This is a static facory method.Construct a translation
Matrixthat translates by the given amounts in thex,y, andzdirections..- Parameters:
x- translation factor for the x-directiony- translation factor for the y-directionz- translation factor for the z-direction- Returns:
- a new
Matrixobject containing a translationMatrix
-
scale
public static Matrix scale(double d)
This is a static facory method.Construct a diagonal
Matrixwith the given number on the diagonal.This is also a uniform scaling matrix.
- Parameters:
d- the diagonal value for the newMatrix- Returns:
- a new
Matrixobject containing a scalingMatrix
-
scale
public static Matrix scale(double x, double y, double z)
This is a static facory method.Construct a (diagonal)
Matrixthat scales in the x, y, and z directions by the given factors.- Parameters:
x- scale factor for the x-directiony- scale factor for the y-directionz- scale factor for the z-direction- Returns:
- a new
Matrixobject containing a scalingMatrix
-
rotateX
public static Matrix rotateX(double theta)
This is a static facory method.Construct a rotation
Matrixthat rotates around the x-axis by the angletheta.- Parameters:
theta- angle (in degrees) to rotate by around the x-axis- Returns:
- a new
Matrixobject containing a rotationMatrix
-
rotateY
public static Matrix rotateY(double theta)
This is a static facory method.Construct a rotation
Matrixthat rotates around the y-axis by the angletheta.- Parameters:
theta- angle (in degrees) to rotate by around the y-axis- Returns:
- a new
Matrixobject containing a rotationMatrix
-
rotateZ
public static Matrix rotateZ(double theta)
This is a static facory method.Construct a rotation
Matrixthat rotates around the z-axis by the angletheta.- Parameters:
theta- angle (in degrees) to rotate by around the z-axis- Returns:
- a new
Matrixobject containing a rotationMatrix
-
rotate
public static Matrix rotate(double theta, double x, double y, double z)
This is a static facory method.Construct a rotation
Matrixthat rotates around the axis vector(x,y,z)by the angletheta.- Parameters:
theta- angle (in degrees) to rotate by around the axis vectorx- x-component of the axis vector for the rotationy- y-component of the axis vector for the rotationz- z-component of the axis vector for the rotation- Returns:
- a new
Matrixobject containing a rotationMatrix
-
times
public Matrix times(double s)
A scalar times thisMatrixreturns a newMatrix.- Parameters:
s- scalar value to multiply thisMatrixby- Returns:
- a new
Matrixobject containing the scalar s times thisMatrix
-
times
public Matrix times(Matrix m)
ThisMatrixtimesMatrixmreturns a newMatrix.- Parameters:
m-Matrixvalue to be multiplied on the right of thisMatrix- Returns:
- new
Matrixobject containing thisMatrixtimesMatrixm
-
rot2euler
public double[] rot2euler()
Assuming that the 3-by-3 "rotation part" of this 4-by-4Matrixrepresents a pure rotation, return the rotation's three Euler angles, in radians, in the order[x, y, z]for rotations in the orderR_z * R_y * R_x.A 3-by-3 matrix is a rotation matrix if its inverse is equal to its transpose and its determinant is equal to 1.
See http://eecs.qmul.ac.uk/~gslabaugh/publications/euler.pdf
- Returns:
- an array of 3 doubles which are this rotation's Euler angles in radians
-
eulerize
public Matrix eulerize()
Assuming that thisMatrixrepresents a 3D rotation, return the rotation matrix formed by multiplying this matrix's three Euler angle rotations in the orderR_z * R_y * R_x.This is mainly for debugging. If this matrix is really a pure rotation, then this method will return a copy of this matrix.
- Returns:
- the "eulerized" version of this
Matrix
-
-