Class Matrix
- java.lang.Object
-
- renderer.scene.Matrix
-
public final class Matrix extends Object
AMatrix
object has fourVector
objects.The four
Vector
objects 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 Matrix
buildFromColumns(Vector c1, Vector c2, Vector c3, Vector c4)
This is a static facory method.static Matrix
buildFromRows(Vector r1, Vector r2, Vector r3, Vector r4)
This is a static facory method.Matrix
eulerize()
Assuming that thisMatrix
represents 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 Matrix
identity()
This is a static facory method.double[]
rot2euler()
Assuming that the 3-by-3 "rotation part" of this 4-by-4Matrix
represents 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 Matrix
rotate(double theta, double x, double y, double z)
This is a static facory method.static Matrix
rotateX(double theta)
This is a static facory method.static Matrix
rotateY(double theta)
This is a static facory method.static Matrix
rotateZ(double theta)
This is a static facory method.static Matrix
scale(double d)
This is a static facory method.static Matrix
scale(double x, double y, double z)
This is a static facory method.Matrix
times(double s)
A scalar times thisMatrix
returns a newMatrix
.Matrix
times(Matrix m)
ThisMatrix
timesMatrix
m
returns a newMatrix
.Vector
times(Vector v)
Vertex
times(Vertex v)
String
toString()
For debugging.static Matrix
translate(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
Matrix
using the given columnVector
s.
-
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
Matrix
using the given rowVector
s.
-
identity
public static Matrix identity()
This is a static facory method.Construct an identity
Matrix
.- Returns:
- a new
Matrix
object containing an identityMatrix
-
translate
public static Matrix translate(double x, double y, double z)
This is a static facory method.Construct a translation
Matrix
that translates by the given amounts in thex
,y
, andz
directions..- Parameters:
x
- translation factor for the x-directiony
- translation factor for the y-directionz
- translation factor for the z-direction- Returns:
- a new
Matrix
object containing a translationMatrix
-
scale
public static Matrix scale(double d)
This is a static facory method.Construct a diagonal
Matrix
with the given number on the diagonal.This is also a uniform scaling matrix.
- Parameters:
d
- the diagonal value for the newMatrix
- Returns:
- a new
Matrix
object containing a scalingMatrix
-
scale
public static Matrix scale(double x, double y, double z)
This is a static facory method.Construct a (diagonal)
Matrix
that 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
Matrix
object containing a scalingMatrix
-
rotateX
public static Matrix rotateX(double theta)
This is a static facory method.Construct a rotation
Matrix
that rotates around the x-axis by the angletheta
.- Parameters:
theta
- angle (in degrees) to rotate by around the x-axis- Returns:
- a new
Matrix
object containing a rotationMatrix
-
rotateY
public static Matrix rotateY(double theta)
This is a static facory method.Construct a rotation
Matrix
that rotates around the y-axis by the angletheta
.- Parameters:
theta
- angle (in degrees) to rotate by around the y-axis- Returns:
- a new
Matrix
object containing a rotationMatrix
-
rotateZ
public static Matrix rotateZ(double theta)
This is a static facory method.Construct a rotation
Matrix
that rotates around the z-axis by the angletheta
.- Parameters:
theta
- angle (in degrees) to rotate by around the z-axis- Returns:
- a new
Matrix
object 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
Matrix
that 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
Matrix
object containing a rotationMatrix
-
times
public Matrix times(double s)
A scalar times thisMatrix
returns a newMatrix
.- Parameters:
s
- scalar value to multiply thisMatrix
by- Returns:
- a new
Matrix
object containing the scalar s times thisMatrix
-
times
public Matrix times(Matrix m)
ThisMatrix
timesMatrix
m
returns a newMatrix
.- Parameters:
m
-Matrix
value to be multiplied on the right of thisMatrix
- Returns:
- new
Matrix
object containing thisMatrix
timesMatrix
m
-
rot2euler
public double[] rot2euler()
Assuming that the 3-by-3 "rotation part" of this 4-by-4Matrix
represents 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 thisMatrix
represents 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
-
-