Package toxi.geom
Class Matrix3d
java.lang.Object
toxi.geom.Matrix3d
- All Implemented Interfaces:
Serializable
,Cloneable
A double precision floating point 3 by 3 matrix. Primarily to support 3D
rotations.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptiondouble
The first matrix element in the first row.double
The second matrix element in the first row.double
The third matrix element in the first row.double
The first matrix element in the second row.double
The second matrix element in the second row.double
The third matrix element in the second row.double
The first matrix element in the third row.double
The second matrix element in the third row.double
The third matrix element in the third row. -
Constructor Summary
ConstructorDescriptionMatrix3d()
Constructs and initializes a Matrix3d to all zeros.Matrix3d
(double[] v) Constructs and initializes a Matrix3d from the specified nine- element array.Matrix3d
(double m00, double m01, double m02, double m10, double m11, double m12, double m20, double m21, double m22) Constructs and initializes a Matrix3d from the specified nine values.Constructs a new matrix with the same values as the Matrix3d parameter. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
add
(double scalar) Adds a scalar to each component of this matrix.final void
Adds a scalar to each component of the matrix m1 and places the result into this.final void
Sets the value of this matrix to the sum of itself and matrix m1.final void
Sets the value of this matrix to the matrix sum of matrices m1 and m2.clone()
Creates a new object of the same class as this object.final double
Computes the determinant of this matrix.boolean
epsilonEquals
(Matrix3d m1, double epsilon) Returns true if the L-infinite distance between this matrix and matrix m1 is less than or equal to the epsilon parameter, otherwise returns false.boolean
Returns true if the Object t1 is of type Matrix3d and all of the data members of t1 are equal to the corresponding data members in this Matrix3d.boolean
Returns true if all of the data members of Matrix3d m1 are equal to the corresponding data members in this Matrix3d.final double
get
(int row, int column) Retrieves the value at the specified row and column of the specified matrix.final void
getColumn
(int column, double[] v) Copies the matrix values in the specified column into the array parameter.final void
Copies the matrix values in the specified column into the vector parameter.final void
getRow
(int row, double[] v) Copies the matrix values in the specified row into the array parameter.final void
Copies the matrix values in the specified row into the vector parameter.final double
getScale()
Performs an SVD normalization of this matrix to calculate and return the uniform scale factor.int
hashCode()
Returns a hash code value based on the data values in this object.final void
invert()
Inverts this matrix in place.final void
Sets the value of this matrix to the matrix inverse of the passed matrix m1.final void
mul
(double scalar) Multiplies each element of this matrix by a scalar.final void
Multiplies each element of matrix m1 by a scalar and places the result into this.final void
Sets the value of this matrix to the result of multiplying itself with matrix m1.final void
Sets the value of this matrix to the result of multiplying the two argument matrices together.final void
mulNormalize
(Matrix3d m1) Multiplies this matrix by matrix m1, does an SVD normalization of the result, and places the result back into this matrix this = SVDnorm(this*m1).final void
mulNormalize
(Matrix3d m1, Matrix3d m2) Multiplies matrix m1 by matrix m2, does an SVD normalization of the result, and places the result into this matrix this = SVDnorm(m1*m2).final void
mulTransposeBoth
(Matrix3d m1, Matrix3d m2) Multiplies the transpose of matrix m1 times the transpose of matrix m2, and places the result into this.final void
mulTransposeLeft
(Matrix3d m1, Matrix3d m2) Multiplies the transpose of matrix m1 times matrix m2, and places the result into this.final void
mulTransposeRight
(Matrix3d m1, Matrix3d m2) Multiplies matrix m1 times the transpose of matrix m2, and places the result into this.final void
negate()
Negates the value of this matrix: this = -this.final void
Sets the value of this matrix equal to the negation of of the Matrix3d parameter.final void
Performs singular value decomposition normalization of this matrix.final void
Perform singular value decomposition normalization of matrix m1 and place the normalized values into this.final void
Perform cross product normalization of this matrix.final void
normalizeCP
(Matrix3d m1) Perform cross product normalization of matrix m1 and place the normalized values into this.final void
rotX
(double angle) Sets the value of this matrix to a counter clockwise rotation about the x axis.final void
rotY
(double angle) Sets the value of this matrix to a counter clockwise rotation about the y axis.final void
rotZ
(double angle) Sets the value of this matrix to a counter clockwise rotation about the z axis.final void
set
(double scale) Sets the value of this matrix to a scale matrix with the passed scale amount.final void
set
(double[] m) Sets the values in this Matrix3d equal to the row-major array parameter (ie, the first three elements of the array will be copied into the first row of this matrix, etc.).final void
Sets the value of this matrix to the value of the Matrix3d argument.final void
set
(Quaternion q1) Sets the value of this matrix to the matrix conversion of the single precision quaternion argument.final void
setColumn
(int column, double[] v) Sets the specified column of this matrix3d to the three values provided.final void
setColumn
(int column, double x, double y, double z) Sets the specified column of this matrix3d to the three values provided.final void
Sets the specified column of this matrix3d to the vector provided.final void
setElement
(int row, int column, double value) Sets the specified element of this matrix3f to the value provided.final void
Sets this Matrix3d to identity.final void
setM00
(double m00) Set the first matrix element in the first row.final void
setM01
(double m01) Set the second matrix element in the first row.final void
setM02
(double m02) Set the third matrix element in the first row.final void
setM10
(double m10) Set first matrix element in the second row.final void
setM11
(double m11) Set the second matrix element in the second row.final void
setM12
(double m12) Set the third matrix element in the second row.final void
setM20
(double m20) Set the first matrix element in the third row.final void
setM21
(double m21) Set the second matrix element in the third row.final void
setM22
(double m22) Set the third matrix element in the third row.final void
setRow
(int row, double[] v) Sets the specified row of this matrix3d to the three values provided.final void
setRow
(int row, double x, double y, double z) Sets the specified row of this matrix3d to the 4 values provided.final void
Sets the specified row of this matrix3d to the Vector provided.final void
setScale
(double scale) Sets the scale component of the current matrix by factoring out the current scale (by doing an SVD) and multiplying by the new scale.final void
setZero()
Sets this matrix to all zeros.final void
Sets the value of this matrix to the matrix difference of itself and matrix m1 (this = this - m1).final void
Sets the value of this matrix to the matrix difference of matrices m1 and m2.toString()
Returns a string that contains the values of this Matrix3d.final void
Multiply this matrix by the tuple t and place the result back into the tuple (t = this*t).final void
Multiply this matrix by the tuple t and and place the result into the tuple "result" (result = this*t).final void
Sets the value of this matrix to its transpose.final void
Sets the value of this matrix to the transpose of the argument matrix.
-
Field Details
-
m00
public double m00The first matrix element in the first row. -
m01
public double m01The second matrix element in the first row. -
m02
public double m02The third matrix element in the first row. -
m10
public double m10The first matrix element in the second row. -
m11
public double m11The second matrix element in the second row. -
m12
public double m12The third matrix element in the second row. -
m20
public double m20The first matrix element in the third row. -
m21
public double m21The second matrix element in the third row. -
m22
public double m22The third matrix element in the third row.
-
-
Constructor Details
-
Matrix3d
public Matrix3d()Constructs and initializes a Matrix3d to all zeros. -
Matrix3d
public Matrix3d(double m00, double m01, double m02, double m10, double m11, double m12, double m20, double m21, double m22) Constructs and initializes a Matrix3d from the specified nine values.- Parameters:
m00
- the [0][0] elementm01
- the [0][1] elementm02
- the [0][2] elementm10
- the [1][0] elementm11
- the [1][1] elementm12
- the [1][2] elementm20
- the [2][0] elementm21
- the [2][1] elementm22
- the [2][2] element
-
Matrix3d
public Matrix3d(double[] v) Constructs and initializes a Matrix3d from the specified nine- element array.- Parameters:
v
- the array of length 9 containing in order
-
Matrix3d
Constructs a new matrix with the same values as the Matrix3d parameter.- Parameters:
m1
- the source matrix
-
-
Method Details
-
add
public final void add(double scalar) Adds a scalar to each component of this matrix.- Parameters:
scalar
- the scalar adder
-
add
Adds a scalar to each component of the matrix m1 and places the result into this. Matrix m1 is not modified.- Parameters:
scalar
- the scalar adderm1
- the original matrix values
-
add
Sets the value of this matrix to the sum of itself and matrix m1.- Parameters:
m1
- the other matrix
-
add
Sets the value of this matrix to the matrix sum of matrices m1 and m2.- Parameters:
m1
- the first matrixm2
- the second matrix
-
clone
Creates a new object of the same class as this object.- Returns:
- a clone of this instance.
- Throws:
OutOfMemoryError
- if there is not enough memory.- Since:
- vecmath 1.3
- See Also:
-
determinant
public final double determinant()Computes the determinant of this matrix.- Returns:
- the determinant of the matrix
-
epsilonEquals
Returns true if the L-infinite distance between this matrix and matrix m1 is less than or equal to the epsilon parameter, otherwise returns false. The L-infinite distance is equal to MAX[i=0,1,2 ; j=0,1,2 ; abs(this.m(i,j) - m1.m(i,j)]- Parameters:
m1
- the matrix to be compared to this matrixepsilon
- the threshold value
-
equals
Returns true if all of the data members of Matrix3d m1 are equal to the corresponding data members in this Matrix3d.- Parameters:
m1
- the matrix with which the comparison is made- Returns:
- true or false
-
equals
Returns true if the Object t1 is of type Matrix3d and all of the data members of t1 are equal to the corresponding data members in this Matrix3d. -
get
public final double get(int row, int column) Retrieves the value at the specified row and column of the specified matrix.- Parameters:
row
- the row number to be retrieved (zero indexed)column
- the column number to be retrieved (zero indexed)- Returns:
- the value at the indexed element.
-
getColumn
public final void getColumn(int column, double[] v) Copies the matrix values in the specified column into the array parameter.- Parameters:
column
- the matrix columnv
- the array into which the matrix row values will be copied
-
getColumn
Copies the matrix values in the specified column into the vector parameter.- Parameters:
column
- the matrix columnv
- the vector into which the matrix row values will be copied
-
getRow
public final void getRow(int row, double[] v) Copies the matrix values in the specified row into the array parameter.- Parameters:
row
- the matrix rowv
- the array into which the matrix row values will be copied
-
getRow
Copies the matrix values in the specified row into the vector parameter.- Parameters:
row
- the matrix rowv
- the vector into which the matrix row values will be copied
-
getScale
public final double getScale()Performs an SVD normalization of this matrix to calculate and return the uniform scale factor. If the matrix has non-uniform scale factors, the largest of the x, y, and z scale factors will be returned. This matrix is not modified.- Returns:
- the scale factor of this matrix
-
hashCode
public int hashCode()Returns a hash code value based on the data values in this object. Two different Matrix3d objects with identical data values (i.e., Matrix3d.equals returns true) will return the same hash code value. Two objects with different data members may return the same hash value, although this is not likely. -
invert
public final void invert()Inverts this matrix in place. -
invert
Sets the value of this matrix to the matrix inverse of the passed matrix m1.- Parameters:
m1
- the matrix to be inverted
-
mul
public final void mul(double scalar) Multiplies each element of this matrix by a scalar.- Parameters:
scalar
- The scalar multiplier.
-
mul
Multiplies each element of matrix m1 by a scalar and places the result into this. Matrix m1 is not modified.- Parameters:
scalar
- the scalar multiplierm1
- the original matrix
-
mul
Sets the value of this matrix to the result of multiplying itself with matrix m1.- Parameters:
m1
- the other matrix
-
mul
Sets the value of this matrix to the result of multiplying the two argument matrices together.- Parameters:
m1
- the first matrixm2
- the second matrix
-
mulNormalize
Multiplies this matrix by matrix m1, does an SVD normalization of the result, and places the result back into this matrix this = SVDnorm(this*m1).- Parameters:
m1
- the matrix on the right hand side of the multiplication
-
mulNormalize
Multiplies matrix m1 by matrix m2, does an SVD normalization of the result, and places the result into this matrix this = SVDnorm(m1*m2).- Parameters:
m1
- the matrix on the left hand side of the multiplicationm2
- the matrix on the right hand side of the multiplication
-
mulTransposeBoth
Multiplies the transpose of matrix m1 times the transpose of matrix m2, and places the result into this.- Parameters:
m1
- the matrix on the left hand side of the multiplicationm2
- the matrix on the right hand side of the multiplication
-
mulTransposeLeft
Multiplies the transpose of matrix m1 times matrix m2, and places the result into this.- Parameters:
m1
- the matrix on the left hand side of the multiplicationm2
- the matrix on the right hand side of the multiplication
-
mulTransposeRight
Multiplies matrix m1 times the transpose of matrix m2, and places the result into this.- Parameters:
m1
- the matrix on the left hand side of the multiplicationm2
- the matrix on the right hand side of the multiplication
-
negate
public final void negate()Negates the value of this matrix: this = -this. -
negate
Sets the value of this matrix equal to the negation of of the Matrix3d parameter.- Parameters:
m1
- the source matrix
-
normalize
public final void normalize()Performs singular value decomposition normalization of this matrix. -
normalize
Perform singular value decomposition normalization of matrix m1 and place the normalized values into this.- Parameters:
m1
- Provides the matrix values to be normalized
-
normalizeCP
public final void normalizeCP()Perform cross product normalization of this matrix. -
normalizeCP
Perform cross product normalization of matrix m1 and place the normalized values into this.- Parameters:
m1
- Provides the matrix values to be normalized
-
rotX
public final void rotX(double angle) Sets the value of this matrix to a counter clockwise rotation about the x axis.- Parameters:
angle
- the angle to rotate about the X axis in radians
-
rotY
public final void rotY(double angle) Sets the value of this matrix to a counter clockwise rotation about the y axis.- Parameters:
angle
- the angle to rotate about the Y axis in radians
-
rotZ
public final void rotZ(double angle) Sets the value of this matrix to a counter clockwise rotation about the z axis.- Parameters:
angle
- the angle to rotate about the Z axis in radians
-
set
public final void set(double scale) Sets the value of this matrix to a scale matrix with the passed scale amount.- Parameters:
scale
- the scale factor for the matrix
-
set
public final void set(double[] m) Sets the values in this Matrix3d equal to the row-major array parameter (ie, the first three elements of the array will be copied into the first row of this matrix, etc.).- Parameters:
m
- the double precision array of length 9
-
set
Sets the value of this matrix to the value of the Matrix3d argument.- Parameters:
m1
- the source matrix3d
-
set
Sets the value of this matrix to the matrix conversion of the single precision quaternion argument.- Parameters:
q1
- the quaternion to be converted
-
setColumn
public final void setColumn(int column, double[] v) Sets the specified column of this matrix3d to the three values provided.- Parameters:
column
- the column number to be modified (zero indexed)v
- the replacement column
-
setColumn
public final void setColumn(int column, double x, double y, double z) Sets the specified column of this matrix3d to the three values provided.- Parameters:
column
- the column number to be modified (zero indexed)x
- the first row elementy
- the second row elementz
- the third row element
-
setColumn
Sets the specified column of this matrix3d to the vector provided.- Parameters:
column
- the column number to be modified (zero indexed)v
- the replacement column
-
setElement
public final void setElement(int row, int column, double value) Sets the specified element of this matrix3f to the value provided.- Parameters:
row
- the row number to be modified (zero indexed)column
- the column number to be modified (zero indexed)value
- the new value
-
setIdentity
public final void setIdentity()Sets this Matrix3d to identity. -
setM00
public final void setM00(double m00) Set the first matrix element in the first row.- Parameters:
m00
- The m00 to set.- Since:
- vecmath 1.5
-
setM01
public final void setM01(double m01) Set the second matrix element in the first row.- Parameters:
m01
- The m01 to set.- Since:
- vecmath 1.5
-
setM02
public final void setM02(double m02) Set the third matrix element in the first row.- Parameters:
m02
- The m02 to set.- Since:
- vecmath 1.5
-
setM10
public final void setM10(double m10) Set first matrix element in the second row.- Parameters:
m10
- The m10 to set.- Since:
- vecmath 1.5
-
setM11
public final void setM11(double m11) Set the second matrix element in the second row.- Parameters:
m11
- The m11 to set.- Since:
- vecmath 1.5
-
setM12
public final void setM12(double m12) Set the third matrix element in the second row.- Parameters:
m12
- The m12 to set.- Since:
- vecmath 1.5
-
setM20
public final void setM20(double m20) Set the first matrix element in the third row.- Parameters:
m20
- The m20 to set.- Since:
- vecmath 1.5
-
setM21
public final void setM21(double m21) Set the second matrix element in the third row.- Parameters:
m21
- The m21 to set.- Since:
- vecmath 1.5
-
setM22
public final void setM22(double m22) Set the third matrix element in the third row.- Parameters:
m22
- The m22 to set.- Since:
- vecmath 1.5
-
setRow
public final void setRow(int row, double[] v) Sets the specified row of this matrix3d to the three values provided.- Parameters:
row
- the row number to be modified (zero indexed)v
- the replacement row
-
setRow
public final void setRow(int row, double x, double y, double z) Sets the specified row of this matrix3d to the 4 values provided.- Parameters:
row
- the row number to be modified (zero indexed)x
- the first column elementy
- the second column elementz
- the third column element
-
setRow
Sets the specified row of this matrix3d to the Vector provided.- Parameters:
row
- the row number to be modified (zero indexed)v
- the replacement row
-
setScale
public final void setScale(double scale) Sets the scale component of the current matrix by factoring out the current scale (by doing an SVD) and multiplying by the new scale.- Parameters:
scale
- the new scale amount
-
setZero
public final void setZero()Sets this matrix to all zeros. -
sub
Sets the value of this matrix to the matrix difference of itself and matrix m1 (this = this - m1).- Parameters:
m1
- the other matrix
-
sub
Sets the value of this matrix to the matrix difference of matrices m1 and m2.- Parameters:
m1
- the first matrixm2
- the second matrix
-
toString
Returns a string that contains the values of this Matrix3d. -
transform
Multiply this matrix by the tuple t and place the result back into the tuple (t = this*t).- Parameters:
t
- the tuple to be multiplied by this matrix and then replaced
-
transform
Multiply this matrix by the tuple t and and place the result into the tuple "result" (result = this*t).- Parameters:
t
- the tuple to be multiplied by this matrixresult
- the tuple into which the product is placed
-
transpose
public final void transpose()Sets the value of this matrix to its transpose. -
transpose
Sets the value of this matrix to the transpose of the argument matrix.- Parameters:
m1
- the matrix to be transposed
-