Class Matrix2d
- All Implemented Interfaces:
Externalizable
,Serializable
,Cloneable
,Matrix2dc
m00 m10
m01 m11
- Author:
- Joseph Burton
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorDescriptionMatrix2d()
Matrix2d
(double m00, double m01, double m10, double m11) Create a new 2x2 matrix using the supplied double values.Matrix2d
(DoubleBuffer buffer) Create a newMatrix2d
by reading its 4 double components from the givenDoubleBuffer
at the buffer's current position.Create a newMatrix2d
and make it a copy of the given matrix.Create a newMatrix2d
and initialize it with the values from the given matrix.Create a newMatrix2d
and initialize its two columns using the supplied vectors. -
Method Summary
Modifier and TypeMethodDescriptionComponent-wise addthis
andother
.Component-wise addthis
andother
and store the result indest
.clone()
double
Return the determinant of this matrix.boolean
boolean
Compare the matrix elements ofthis
matrix with the given matrix using the givendelta
and return whether all of them are equal within a maximum difference ofdelta
.double[]
get
(double[] arr) Store this matrix into the supplied double array in column-major order.double[]
get
(double[] arr, int offset) Store this matrix into the supplied double array in column-major order at the given offset.double
get
(int column, int row) Get the matrix element value at the given column and row.com.google.gwt.typedarrays.shared.Float64Array
get
(int index, com.google.gwt.typedarrays.shared.Float64Array buffer) Store this matrix in column-major order into the suppliedFloat64Array
at the given index.get
(int index, ByteBuffer buffer) Store this matrix in column-major order into the suppliedByteBuffer
starting at the specified absolute buffer position/index.get
(int index, DoubleBuffer buffer) Store this matrix in column-major order into the suppliedDoubleBuffer
starting at the specified absolute buffer position/index.com.google.gwt.typedarrays.shared.Float64Array
get
(com.google.gwt.typedarrays.shared.Float64Array buffer) Store this matrix in column-major order into the suppliedFloat64Array
.get
(ByteBuffer buffer) Store this matrix in column-major order into the suppliedByteBuffer
at the current bufferposition
.get
(DoubleBuffer buffer) Store this matrix in column-major order into the suppliedDoubleBuffer
at the current bufferposition
.Get the current values ofthis
matrix and store them intodest
.Get the current values ofthis
matrix and store them as the rotational component ofdest
.get
(Matrix3x2d dest) Get the current values ofthis
matrix and store them as the rotational component ofdest
.Get the column at the givencolumn
index, starting with0
.getFloats
(int index, ByteBuffer buffer) Store the elements of this matrix as float values in column-major order into the suppliedByteBuffer
starting at the specified absolute buffer position/index.getFloats
(ByteBuffer buffer) Store the elements of this matrix as float values in column-major order into the suppliedByteBuffer
at the current bufferposition
.double
Get the angle of the rotation component ofthis
matrix.Get the row at the givenrow
index, starting with0
.Get the scaling factors ofthis
matrix for the three base axes.getToAddress
(long address) Store this matrix in column-major order at the given off-heap address.getTransposed
(int index, ByteBuffer buffer) Store this matrix in row-major order into the suppliedByteBuffer
starting at the specified absolute buffer position/index.getTransposed
(int index, DoubleBuffer buffer) Store this matrix in row-major order into the suppliedDoubleBuffer
starting at the specified absolute buffer position/index.getTransposed
(int index, FloatBuffer buffer) Store this matrix in row-major order into the suppliedFloatBuffer
starting at the specified absolute buffer position/index.getTransposed
(ByteBuffer buffer) Store this matrix in row-major order into the suppliedByteBuffer
at the current bufferposition
.getTransposed
(DoubleBuffer buffer) Store this matrix in row-major order into the suppliedDoubleBuffer
at the current bufferposition
.getTransposed
(FloatBuffer buffer) Store this matrix in row-major order into the suppliedFloatBuffer
at the current bufferposition
.getTransposedFloats
(int index, ByteBuffer buffer) Store this matrix in row-major order into the suppliedByteBuffer
starting at the specified absolute buffer position/index.getTransposedFloats
(ByteBuffer buffer) Store this matrix as float values in row-major order into the suppliedByteBuffer
at the current bufferposition
.int
hashCode()
identity()
Set this matrix to the identity.invert()
Invert this matrix.Invert thethis
matrix and store the result indest
.boolean
isFinite()
Linearly interpolatethis
andother
using the given interpolation factort
and store the result inthis
.Linearly interpolatethis
andother
using the given interpolation factort
and store the result indest
.double
m00()
Return the value of the matrix element at column 0 and row 0.m00
(double m00) Set the value of the matrix element at column 0 and row 0.double
m01()
Return the value of the matrix element at column 0 and row 1.m01
(double m01) Set the value of the matrix element at column 0 and row 1.double
m10()
Return the value of the matrix element at column 1 and row 0.m10
(double m10) Set the value of the matrix element at column 1 and row 0.double
m11()
Return the value of the matrix element at column 1 and row 1.m11
(double m11) Set the value of the matrix element at column 1 and row 1.Multiply this matrix by the suppliedright
matrix.Multiply this matrix by the suppliedright
matrix and store the result indest
.Multiply this matrix by the suppliedright
matrix.Multiply this matrix by the suppliedright
matrix and store the result indest
.mulComponentWise
(Matrix2dc other) Component-wise multiplythis
byother
.mulComponentWise
(Matrix2dc other, Matrix2d dest) Component-wise multiplythis
byother
and store the result indest
.Pre-multiply this matrix by the suppliedleft
matrix and store the result inthis
.Pre-multiply this matrix by the suppliedleft
matrix and store the result indest
.normal()
Setthis
matrix to its own normal matrix.Compute a normal matrix fromthis
matrix and store it intodest
.Obtain the direction of+X
before the transformation represented bythis
orthogonal matrix is applied.Obtain the direction of+Y
before the transformation represented bythis
orthogonal matrix is applied.Obtain the direction of+X
before the transformation represented bythis
matrix is applied.Obtain the direction of+Y
before the transformation represented bythis
matrix is applied.void
rotate
(double angle) Apply rotation about the origin to this matrix by rotating the given amount of radians.Apply rotation to this matrix by rotating the given amount of radians and store the result indest
.rotateLocal
(double angle) Pre-multiply a rotation to this matrix by rotating the given amount of radians about the origin.rotateLocal
(double angle, Matrix2d dest) Pre-multiply a rotation to this matrix by rotating the given amount of radians and store the result indest
.rotation
(double angle) Set this matrix to a rotation matrix which rotates the given radians about the origin.scale
(double xy) Apply scaling to this matrix by uniformly scaling all base axes by the givenxy
factor.scale
(double x, double y) Apply scaling to this matrix by scaling the base axes by the given x and y factors.Apply scaling to this matrix by scaling the base axes by the given x and y factors and store the result indest
.Apply scaling to this matrix by uniformly scaling all base axes by the givenxy
factor and store the result indest
.Apply scaling to this matrix by scaling the base axes by the givenxy.x
andxy.y
factors, respectively.Apply scaling tothis
matrix by scaling the base axes by the givenxy.x
andxy.y
factors, respectively and store the result indest
.scaleLocal
(double x, double y) Pre-multiply scaling to this matrix by scaling the base axes by the given x and y factors.scaleLocal
(double x, double y, Matrix2d dest) Pre-multiply scaling tothis
matrix by scaling the base axes by the given x and y factors and store the result indest
.scaling
(double factor) Set this matrix to be a simple scale matrix, which scales all axes uniformly by the given factor.scaling
(double x, double y) Set this matrix to be a simple scale matrix.Set this matrix to be a simple scale matrix which scales the base axes byxy.x
andxy.y
respectively.set
(double[] m) Set the values in this matrix based on the supplied double array.set
(double m00, double m01, double m10, double m11) Set the values within this matrix to the supplied double values.set
(int column, int row, double value) Set the matrix element at the given column and row to the specified value.set
(int index, ByteBuffer buffer) Set the values of this matrix by reading 4 double values from the givenByteBuffer
in column-major order, starting at the specified absolute buffer position/index.set
(int index, DoubleBuffer buffer) Set the values of this matrix by reading 4 double values from the givenDoubleBuffer
in column-major order, starting at the specified absolute buffer position/index.set
(ByteBuffer buffer) Set the values of this matrix by reading 4 double values from the givenByteBuffer
in column-major order, starting at its current position.set
(DoubleBuffer buffer) Set the values of this matrix by reading 4 double values from the givenDoubleBuffer
in column-major order, starting at its current position.Set the elements of this matrix to the ones inm
.Set the elements of this matrix to the ones inm
.Set the elements of this matrix to the upper left 2x2 of the givenMatrix3dc
.Set the elements of this matrix to the upper left 2x2 of the givenMatrix3dc
.set
(Matrix3x2dc m) Set the elements of this matrix to the left 2x2 submatrix ofm
.set
(Matrix3x2fc m) Set the elements of this matrix to the left 2x2 submatrix ofm
.Set the two columns of this matrix to the supplied vectors, respectively.setColumn
(int column, double x, double y) Set the column at the givencolumn
index, starting with0
.Set the column at the givencolumn
index, starting with0
.setFromAddress
(long address) Set the values of this matrix by reading 4 double values from off-heap memory in column-major order, starting at the given address.setRow
(int row, double x, double y) Set the row at the givenrow
index, starting with0
.Set the row at the givenrow
index, starting with0
.Component-wise subtractsubtrahend
fromthis
.Component-wise subtractsubtrahend
fromthis
and store the result indest
.Exchange the values ofthis
matrix with the givenother
matrix.toString()
Return a string representation of this matrix.toString
(NumberFormat formatter) Return a string representation of this matrix by formatting the matrix elements with the givenNumberFormat
.Transform the vector(x, y)
by this matrix and store the result indest
.Transform the given vector by this matrix.Transform the given vector by this matrix and store the result indest
.transformTranspose
(double x, double y, Vector2d dest) Transform the vector(x, y)
by the transpose of this matrix and store the result indest
.Transform the given vector by the transpose of this matrix.transformTranspose
(Vector2dc v, Vector2d dest) Transform the given vector by the transpose of this matrix and store the result indest
.Transpose this matrix.Transposethis
matrix and store the result indest
.void
zero()
Set all values within this matrix to zero.
-
Field Details
-
m00
public double m00 -
m01
public double m01 -
m10
public double m10 -
m11
public double m11
-
-
Constructor Details
-
Matrix2d
public Matrix2d() -
Matrix2d
Create a newMatrix2d
and make it a copy of the given matrix.- Parameters:
mat
- theMatrix2dc
to copy the values from
-
Matrix2d
Create a newMatrix2d
and initialize it with the values from the given matrix.- Parameters:
mat
- the matrix to initialize this matrix with
-
Matrix2d
- Parameters:
mat
- theMatrix3dc
to copy the values from
-
Matrix2d
- Parameters:
mat
- theMatrix3fc
to copy the values from
-
Matrix2d
public Matrix2d(double m00, double m01, double m10, double m11) Create a new 2x2 matrix using the supplied double values. The order of the parameter is column-major, so the first two parameters specify the two elements of the first column.- Parameters:
m00
- the value of m00m01
- the value of m01m10
- the value of m10m11
- the value of m11
-
Matrix2d
Create a newMatrix2d
by reading its 4 double components from the givenDoubleBuffer
at the buffer's current position.That DoubleBuffer is expected to hold the values in column-major order.
The buffer's position will not be changed by this method.
- Parameters:
buffer
- theDoubleBuffer
to read the matrix values from
-
Matrix2d
Create a newMatrix2d
and initialize its two columns using the supplied vectors.- Parameters:
col0
- the first columncol1
- the second column
-
-
Method Details
-
m00
public double m00()Description copied from interface:Matrix2dc
Return the value of the matrix element at column 0 and row 0. -
m01
public double m01()Description copied from interface:Matrix2dc
Return the value of the matrix element at column 0 and row 1. -
m10
public double m10()Description copied from interface:Matrix2dc
Return the value of the matrix element at column 1 and row 0. -
m11
public double m11()Description copied from interface:Matrix2dc
Return the value of the matrix element at column 1 and row 1. -
m00
Set the value of the matrix element at column 0 and row 0.- Parameters:
m00
- the new value- Returns:
- this
-
m01
Set the value of the matrix element at column 0 and row 1.- Parameters:
m01
- the new value- Returns:
- this
-
m10
Set the value of the matrix element at column 1 and row 0.- Parameters:
m10
- the new value- Returns:
- this
-
m11
Set the value of the matrix element at column 1 and row 1.- Parameters:
m11
- the new value- Returns:
- this
-
set
Set the elements of this matrix to the ones inm
.- Parameters:
m
- the matrix to copy the elements from- Returns:
- this
-
set
Set the elements of this matrix to the ones inm
.- Parameters:
m
- the matrix to copy the elements from- Returns:
- this
-
set
Set the elements of this matrix to the left 2x2 submatrix ofm
.- Parameters:
m
- the matrix to copy the elements from- Returns:
- this
-
set
Set the elements of this matrix to the left 2x2 submatrix ofm
.- Parameters:
m
- the matrix to copy the elements from- Returns:
- this
-
set
Set the elements of this matrix to the upper left 2x2 of the givenMatrix3dc
.- Parameters:
m
- theMatrix3dc
to copy the values from- Returns:
- this
-
set
Set the elements of this matrix to the upper left 2x2 of the givenMatrix3dc
.- Parameters:
m
- theMatrix3fc
to copy the values from- Returns:
- this
-
mul
Multiply this matrix by the suppliedright
matrix.If
M
isthis
matrix andR
theright
matrix, then the new matrix will beM * R
. So when transforming a vectorv
with the new matrix by usingM * R * v
, the transformation of the right matrix will be applied first!- Parameters:
right
- the right operand of the matrix multiplication- Returns:
- this
-
mul
Description copied from interface:Matrix2dc
Multiply this matrix by the suppliedright
matrix and store the result indest
.If
M
isthis
matrix andR
theright
matrix, then the new matrix will beM * R
. So when transforming a vectorv
with the new matrix by usingM * R * v
, the transformation of the right matrix will be applied first! -
mul
Multiply this matrix by the suppliedright
matrix.If
M
isthis
matrix andR
theright
matrix, then the new matrix will beM * R
. So when transforming a vectorv
with the new matrix by usingM * R * v
, the transformation of the right matrix will be applied first!- Parameters:
right
- the right operand of the matrix multiplication- Returns:
- this
-
mul
Description copied from interface:Matrix2dc
Multiply this matrix by the suppliedright
matrix and store the result indest
.If
M
isthis
matrix andR
theright
matrix, then the new matrix will beM * R
. So when transforming a vectorv
with the new matrix by usingM * R * v
, the transformation of the right matrix will be applied first! -
mulLocal
Pre-multiply this matrix by the suppliedleft
matrix and store the result inthis
.If
M
isthis
matrix andL
theleft
matrix, then the new matrix will beL * M
. So when transforming a vectorv
with the new matrix by usingL * M * v
, the transformation ofthis
matrix will be applied first!- Parameters:
left
- the left operand of the matrix multiplication- Returns:
- this
-
mulLocal
Description copied from interface:Matrix2dc
Pre-multiply this matrix by the suppliedleft
matrix and store the result indest
.If
M
isthis
matrix andL
theleft
matrix, then the new matrix will beL * M
. So when transforming a vectorv
with the new matrix by usingL * M * v
, the transformation ofthis
matrix will be applied first! -
set
Set the values within this matrix to the supplied double values. The result looks like this:m00, m10
m01, m11- Parameters:
m00
- the new value of m00m01
- the new value of m01m10
- the new value of m10m11
- the new value of m11- Returns:
- this
-
set
Set the values in this matrix based on the supplied double array. The result looks like this:0, 2
1, 3
This method only uses the first 4 values, all others are ignored.- Parameters:
m
- the array to read the matrix values from- Returns:
- this
-
set
Set the two columns of this matrix to the supplied vectors, respectively.- Parameters:
col0
- the first columncol1
- the second column- Returns:
- this
-
determinant
public double determinant()Description copied from interface:Matrix2dc
Return the determinant of this matrix.- Specified by:
determinant
in interfaceMatrix2dc
- Returns:
- the determinant
-
invert
Invert this matrix.- Returns:
- this
-
invert
Description copied from interface:Matrix2dc
Invert thethis
matrix and store the result indest
. -
transpose
Transpose this matrix.- Returns:
- this
-
transpose
Description copied from interface:Matrix2dc
Transposethis
matrix and store the result indest
. -
toString
Return a string representation of this matrix.This method creates a new
DecimalFormat
on every invocation with the format string "0.000E0;-
". -
toString
Return a string representation of this matrix by formatting the matrix elements with the givenNumberFormat
.- Parameters:
formatter
- theNumberFormat
used to format the matrix values with- Returns:
- the string representation
-
get
Get the current values ofthis
matrix and store them intodest
.This is the reverse method of
set(Matrix2dc)
and allows to obtain intermediate calculation results when chaining multiple transformations. -
get
Description copied from interface:Matrix2dc
Get the current values ofthis
matrix and store them as the rotational component ofdest
. All other values ofdest
will be set to 0. -
get
Description copied from interface:Matrix2dc
Get the current values ofthis
matrix and store them as the rotational component ofdest
. All other values ofdest
will be set to identity. -
getRotation
public double getRotation()Description copied from interface:Matrix2dc
Get the angle of the rotation component ofthis
matrix.This method assumes that there is a valid rotation to be returned, i.e. that
atan2(-m10, m00) == atan2(m01, m11)
.- Specified by:
getRotation
in interfaceMatrix2dc
- Returns:
- the angle
-
get
Description copied from interface:Matrix2dc
Store this matrix in column-major order into the suppliedDoubleBuffer
at the current bufferposition
.This method will not increment the position of the given DoubleBuffer.
In order to specify the offset into the DoubleBuffer at which the matrix is stored, use
Matrix2dc.get(int, DoubleBuffer)
, taking the absolute position as parameter. -
get
Description copied from interface:Matrix2dc
Store this matrix in column-major order into the suppliedDoubleBuffer
starting at the specified absolute buffer position/index.This method will not increment the position of the given DoubleBuffer.
-
get
Description copied from interface:Matrix2dc
Store this matrix in column-major order into the suppliedByteBuffer
at the current bufferposition
.This method will not increment the position of the given ByteBuffer.
In order to specify the offset into the ByteBuffer at which the matrix is stored, use
Matrix2dc.get(int, ByteBuffer)
, taking the absolute position as parameter. -
get
Description copied from interface:Matrix2dc
Store this matrix in column-major order into the suppliedByteBuffer
starting at the specified absolute buffer position/index.This method will not increment the position of the given ByteBuffer.
-
getFloats
Description copied from interface:Matrix2dc
Store the elements of this matrix as float values in column-major order into the suppliedByteBuffer
at the current bufferposition
.This method will not increment the position of the given ByteBuffer.
Please note that due to this matrix storing double values those values will potentially lose precision when they are converted to float values before being put into the given ByteBuffer.
In order to specify the offset into the ByteBuffer at which the matrix is stored, use
Matrix2dc.getFloats(int, ByteBuffer)
, taking the absolute position as parameter. -
getFloats
Description copied from interface:Matrix2dc
Store the elements of this matrix as float values in column-major order into the suppliedByteBuffer
starting at the specified absolute buffer position/index.This method will not increment the position of the given ByteBuffer.
Please note that due to this matrix storing double values those values will potentially lose precision when they are converted to float values before being put into the given ByteBuffer.
-
getTransposed
Description copied from interface:Matrix2dc
Store this matrix in row-major order into the suppliedDoubleBuffer
at the current bufferposition
.This method will not increment the position of the given DoubleBuffer.
In order to specify the offset into the DoubleBuffer at which the matrix is stored, use
Matrix2dc.getTransposed(int, DoubleBuffer)
, taking the absolute position as parameter.- Specified by:
getTransposed
in interfaceMatrix2dc
- Parameters:
buffer
- will receive the values of this matrix in row-major order at its current position- Returns:
- the passed in buffer
- See Also:
-
getTransposed
Description copied from interface:Matrix2dc
Store this matrix in row-major order into the suppliedDoubleBuffer
starting at the specified absolute buffer position/index.This method will not increment the position of the given DoubleBuffer.
- Specified by:
getTransposed
in interfaceMatrix2dc
- Parameters:
index
- the absolute position into the DoubleBufferbuffer
- will receive the values of this matrix in row-major order- Returns:
- the passed in buffer
-
getTransposed
Description copied from interface:Matrix2dc
Store this matrix in row-major order into the suppliedFloatBuffer
at the current bufferposition
.This method will not increment the position of the given FloatBuffer.
Please note that due to this matrix storing double values those values will potentially lose precision when they are converted to float values before being put into the given FloatBuffer.
In order to specify the offset into the FloatBuffer at which the matrix is stored, use
Matrix2dc.getTransposed(int, FloatBuffer)
, taking the absolute position as parameter.- Specified by:
getTransposed
in interfaceMatrix2dc
- Parameters:
buffer
- will receive the values of this matrix in row-major order at its current position- Returns:
- the passed in buffer
- See Also:
-
getTransposed
Description copied from interface:Matrix2dc
Store this matrix in row-major order into the suppliedFloatBuffer
starting at the specified absolute buffer position/index.This method will not increment the position of the given FloatBuffer.
Please note that due to this matrix storing double values those values will potentially lose precision when they are converted to float values before being put into the given FloatBuffer.
- Specified by:
getTransposed
in interfaceMatrix2dc
- Parameters:
index
- the absolute position into the FloatBufferbuffer
- will receive the values of this matrix in row-major order- Returns:
- the passed in buffer
-
getTransposed
Description copied from interface:Matrix2dc
Store this matrix in row-major order into the suppliedByteBuffer
at the current bufferposition
.This method will not increment the position of the given ByteBuffer.
In order to specify the offset into the ByteBuffer at which the matrix is stored, use
Matrix2dc.getTransposed(int, ByteBuffer)
, taking the absolute position as parameter.- Specified by:
getTransposed
in interfaceMatrix2dc
- Parameters:
buffer
- will receive the values of this matrix in row-major order at its current position- Returns:
- the passed in buffer
- See Also:
-
getTransposed
Description copied from interface:Matrix2dc
Store this matrix in row-major order into the suppliedByteBuffer
starting at the specified absolute buffer position/index.This method will not increment the position of the given ByteBuffer.
- Specified by:
getTransposed
in interfaceMatrix2dc
- Parameters:
index
- the absolute position into the ByteBufferbuffer
- will receive the values of this matrix in row-major order- Returns:
- the passed in buffer
-
getTransposedFloats
Description copied from interface:Matrix2dc
Store this matrix as float values in row-major order into the suppliedByteBuffer
at the current bufferposition
.This method will not increment the position of the given ByteBuffer.
Please note that due to this matrix storing double values those values will potentially lose precision when they are converted to float values before being put into the given FloatBuffer.
In order to specify the offset into the ByteBuffer at which the matrix is stored, use
Matrix2dc.getTransposedFloats(int, ByteBuffer)
, taking the absolute position as parameter.- Specified by:
getTransposedFloats
in interfaceMatrix2dc
- Parameters:
buffer
- will receive the values of this matrix as float values in row-major order at its current position- Returns:
- the passed in buffer
- See Also:
-
getTransposedFloats
Description copied from interface:Matrix2dc
Store this matrix in row-major order into the suppliedByteBuffer
starting at the specified absolute buffer position/index.This method will not increment the position of the given ByteBuffer.
Please note that due to this matrix storing double values those values will potentially lose precision when they are converted to float values before being put into the given FloatBuffer.
- Specified by:
getTransposedFloats
in interfaceMatrix2dc
- Parameters:
index
- the absolute position into the ByteBufferbuffer
- will receive the values of this matrix as float values in row-major order- Returns:
- the passed in buffer
-
getToAddress
Description copied from interface:Matrix2dc
Store this matrix in column-major order at the given off-heap address.This method will throw an
UnsupportedOperationException
when JOML is used with `-Djoml.nounsafe`.This method is unsafe as it can result in a crash of the JVM process when the specified address range does not belong to this process.
- Specified by:
getToAddress
in interfaceMatrix2dc
- Parameters:
address
- the off-heap address where to store this matrix- Returns:
- this
-
get
public double[] get(double[] arr, int offset) Description copied from interface:Matrix2dc
Store this matrix into the supplied double array in column-major order at the given offset. -
get
public double[] get(double[] arr) Description copied from interface:Matrix2dc
Store this matrix into the supplied double array in column-major order.In order to specify an explicit offset into the array, use the method
Matrix2dc.get(double[], int)
. -
set
Set the values of this matrix by reading 4 double values from the givenDoubleBuffer
in column-major order, starting at its current position.The DoubleBuffer is expected to contain the values in column-major order.
The position of the DoubleBuffer will not be changed by this method.
- Parameters:
buffer
- the DoubleBuffer to read the matrix values from in column-major order- Returns:
- this
-
set
Set the values of this matrix by reading 4 double values from the givenByteBuffer
in column-major order, starting at its current position.The ByteBuffer is expected to contain the values in column-major order.
The position of the ByteBuffer will not be changed by this method.
- Parameters:
buffer
- the ByteBuffer to read the matrix values from in column-major order- Returns:
- this
-
set
Set the values of this matrix by reading 4 double values from the givenDoubleBuffer
in column-major order, starting at the specified absolute buffer position/index.The DoubleBuffer is expected to contain the values in column-major order.
The position of the DoubleBuffer will not be changed by this method.
- Parameters:
index
- the absolute position into the DoubleBufferbuffer
- the DoubleBuffer to read the matrix values from in column-major order- Returns:
- this
-
set
Set the values of this matrix by reading 4 double values from the givenByteBuffer
in column-major order, starting at the specified absolute buffer position/index.The ByteBuffer is expected to contain the values in column-major order.
The position of the ByteBuffer will not be changed by this method.
- Parameters:
index
- the absolute position into the ByteBufferbuffer
- the ByteBuffer to read the matrix values from in column-major order- Returns:
- this
-
setFromAddress
Set the values of this matrix by reading 4 double values from off-heap memory in column-major order, starting at the given address.This method will throw an
UnsupportedOperationException
when JOML is used with `-Djoml.nounsafe`.This method is unsafe as it can result in a crash of the JVM process when the specified address range does not belong to this process.
- Parameters:
address
- the off-heap memory address to read the matrix values from in column-major order- Returns:
- this
-
zero
Set all values within this matrix to zero.- Returns:
- this
-
identity
Set this matrix to the identity.- Returns:
- this
-
scale
Description copied from interface:Matrix2dc
Apply scaling tothis
matrix by scaling the base axes by the givenxy.x
andxy.y
factors, respectively and store the result indest
.If
M
isthis
matrix andS
the scaling matrix, then the new matrix will beM * S
. So when transforming a vectorv
with the new matrix by usingM * S * v
, the scaling will be applied first! -
scale
Apply scaling to this matrix by scaling the base axes by the givenxy.x
andxy.y
factors, respectively.If
M
isthis
matrix andS
the scaling matrix, then the new matrix will beM * S
. So when transforming a vectorv
with the new matrix by usingM * S * v
, the scaling will be applied first!- Parameters:
xy
- the factors of the x and y component, respectively- Returns:
- this
-
scale
Description copied from interface:Matrix2dc
Apply scaling to this matrix by scaling the base axes by the given x and y factors and store the result indest
.If
M
isthis
matrix andS
the scaling matrix, then the new matrix will beM * S
. So when transforming a vectorv
with the new matrix by usingM * S * v
, the scaling will be applied first! -
scale
Apply scaling to this matrix by scaling the base axes by the given x and y factors.If
M
isthis
matrix andS
the scaling matrix, then the new matrix will beM * S
. So when transforming a vectorv
with the new matrix by usingM * S * v
, the scaling will be applied first!- Parameters:
x
- the factor of the x componenty
- the factor of the y component- Returns:
- this
-
scale
Description copied from interface:Matrix2dc
Apply scaling to this matrix by uniformly scaling all base axes by the givenxy
factor and store the result indest
.If
M
isthis
matrix andS
the scaling matrix, then the new matrix will beM * S
. So when transforming a vectorv
with the new matrix by usingM * S * v
, the scaling will be applied first! -
scale
Apply scaling to this matrix by uniformly scaling all base axes by the givenxy
factor.If
M
isthis
matrix andS
the scaling matrix, then the new matrix will beM * S
. So when transforming a vectorv
with the new matrix by usingM * S * v
, the scaling will be applied first!- Parameters:
xy
- the factor for all components- Returns:
- this
- See Also:
-
scaleLocal
Description copied from interface:Matrix2dc
Pre-multiply scaling tothis
matrix by scaling the base axes by the given x and y factors and store the result indest
.If
M
isthis
matrix andS
the scaling matrix, then the new matrix will beS * M
. So when transforming a vectorv
with the new matrix by usingS * M * v
, the scaling will be applied last!- Specified by:
scaleLocal
in interfaceMatrix2dc
- Parameters:
x
- the factor of the x componenty
- the factor of the y componentdest
- will hold the result- Returns:
- dest
-
scaleLocal
Pre-multiply scaling to this matrix by scaling the base axes by the given x and y factors.If
M
isthis
matrix andS
the scaling matrix, then the new matrix will beS * M
. So when transforming a vectorv
with the new matrix by usingS * M * v
, the scaling will be applied last!- Parameters:
x
- the factor of the x componenty
- the factor of the y component- Returns:
- this
-
scaling
Set this matrix to be a simple scale matrix, which scales all axes uniformly by the given factor.The resulting matrix can be multiplied against another transformation matrix to obtain an additional scaling.
In order to post-multiply a scaling transformation directly to a matrix, use
scale()
instead.- Parameters:
factor
- the scale factor in x and y- Returns:
- this
- See Also:
-
scaling
Set this matrix to be a simple scale matrix.- Parameters:
x
- the scale in xy
- the scale in y- Returns:
- this
-
scaling
Set this matrix to be a simple scale matrix which scales the base axes byxy.x
andxy.y
respectively.The resulting matrix can be multiplied against another transformation matrix to obtain an additional scaling.
In order to post-multiply a scaling transformation directly to a matrix use
scale()
instead.- Parameters:
xy
- the scale in x and y respectively- Returns:
- this
- See Also:
-
rotation
Set this matrix to a rotation matrix which rotates the given radians about the origin.The produced rotation will rotate a vector counter-clockwise around the origin.
The resulting matrix can be multiplied against another transformation matrix to obtain an additional rotation.
In order to post-multiply a rotation transformation directly to a matrix, use
rotate()
instead.- Parameters:
angle
- the angle in radians- Returns:
- this
- See Also:
-
transform
Description copied from interface:Matrix2dc
Transform the given vector by this matrix. -
transform
Description copied from interface:Matrix2dc
Transform the given vector by this matrix and store the result indest
. -
transform
Description copied from interface:Matrix2dc
Transform the vector(x, y)
by this matrix and store the result indest
. -
transformTranspose
Description copied from interface:Matrix2dc
Transform the given vector by the transpose of this matrix.- Specified by:
transformTranspose
in interfaceMatrix2dc
- Parameters:
v
- the vector to transform- Returns:
- v
-
transformTranspose
Description copied from interface:Matrix2dc
Transform the given vector by the transpose of this matrix and store the result indest
.- Specified by:
transformTranspose
in interfaceMatrix2dc
- Parameters:
v
- the vector to transformdest
- will hold the result- Returns:
- dest
-
transformTranspose
Description copied from interface:Matrix2dc
Transform the vector(x, y)
by the transpose of this matrix and store the result indest
.- Specified by:
transformTranspose
in interfaceMatrix2dc
- Parameters:
x
- the x coordinate of the vector to transformy
- the y coordinate of the vector to transformdest
- will hold the result- Returns:
- dest
-
writeExternal
- Specified by:
writeExternal
in interfaceExternalizable
- Throws:
IOException
-
readExternal
- Specified by:
readExternal
in interfaceExternalizable
- Throws:
IOException
-
rotate
Apply rotation about the origin to this matrix by rotating the given amount of radians.The produced rotation will rotate a vector counter-clockwise around the origin.
If
M
isthis
matrix andR
the rotation matrix, then the new matrix will beM * R
. So when transforming a vectorv
with the new matrix by usingM * R * v
, the rotation will be applied first!Reference: http://en.wikipedia.org
- Parameters:
angle
- the angle in radians- Returns:
- this
-
rotate
Description copied from interface:Matrix2dc
Apply rotation to this matrix by rotating the given amount of radians and store the result indest
.The produced rotation will rotate a vector counter-clockwise around the origin.
If
M
isthis
matrix andR
the rotation matrix, then the new matrix will beM * R
. So when transforming a vectorv
with the new matrix by usingM * R * v
, the rotation will be applied first!Reference: http://en.wikipedia.org
-
rotateLocal
Pre-multiply a rotation to this matrix by rotating the given amount of radians about the origin.The produced rotation will rotate a vector counter-clockwise around the origin.
If
M
isthis
matrix andR
the rotation matrix, then the new matrix will beR * M
. So when transforming a vectorv
with the new matrix by usingR * M * v
, the rotation will be applied last!In order to set the matrix to a rotation matrix without pre-multiplying the rotation transformation, use
rotation()
.Reference: http://en.wikipedia.org
- Parameters:
angle
- the angle in radians to rotate about the X axis- Returns:
- this
- See Also:
-
rotateLocal
Description copied from interface:Matrix2dc
Pre-multiply a rotation to this matrix by rotating the given amount of radians and store the result indest
.The produced rotation will rotate a vector counter-clockwise around the origin.
If
M
isthis
matrix andR
the rotation matrix, then the new matrix will beR * M
. So when transforming a vectorv
with the new matrix by usingR * M * v
, the rotation will be applied last!Reference: http://en.wikipedia.org
- Specified by:
rotateLocal
in interfaceMatrix2dc
- Parameters:
angle
- the angle in radiansdest
- will hold the result- Returns:
- dest
-
getRow
Description copied from interface:Matrix2dc
Get the row at the givenrow
index, starting with0
.- Specified by:
getRow
in interfaceMatrix2dc
- Parameters:
row
- the row index in[0..1]
dest
- will hold the row components- Returns:
- the passed in destination
- Throws:
IndexOutOfBoundsException
- ifrow
is not in[0..1]
-
setRow
Set the row at the givenrow
index, starting with0
.- Parameters:
row
- the row index in[0..1]
src
- the row components to set- Returns:
- this
- Throws:
IndexOutOfBoundsException
- ifrow
is not in[0..1]
-
setRow
Set the row at the givenrow
index, starting with0
.- Parameters:
row
- the row index in[0..1]
x
- the first element in the rowy
- the second element in the row- Returns:
- this
- Throws:
IndexOutOfBoundsException
- ifrow
is not in[0..1]
-
getColumn
Description copied from interface:Matrix2dc
Get the column at the givencolumn
index, starting with0
.- Specified by:
getColumn
in interfaceMatrix2dc
- Parameters:
column
- the column index in[0..1]
dest
- will hold the column components- Returns:
- the passed in destination
- Throws:
IndexOutOfBoundsException
- ifcolumn
is not in[0..1]
-
setColumn
Set the column at the givencolumn
index, starting with0
.- Parameters:
column
- the column index in[0..1]
src
- the column components to set- Returns:
- this
- Throws:
IndexOutOfBoundsException
- ifcolumn
is not in[0..1]
-
setColumn
Set the column at the givencolumn
index, starting with0
.- Parameters:
column
- the column index in[0..1]
x
- the first element in the columny
- the second element in the column- Returns:
- this
- Throws:
IndexOutOfBoundsException
- ifcolumn
is not in[0..1]
-
get
public double get(int column, int row) Description copied from interface:Matrix2dc
Get the matrix element value at the given column and row. -
set
Set the matrix element at the given column and row to the specified value.- Parameters:
column
- the colum index in[0..1]
row
- the row index in[0..1]
value
- the value- Returns:
- this
-
normal
Setthis
matrix to its own normal matrix.Please note that, if
this
is an orthogonal matrix or a matrix whose columns are orthogonal vectors, then this method need not be invoked, since in that casethis
itself is its normal matrix. In this case, useset(Matrix2dc)
to set a given Matrix2d to this matrix.- Returns:
- this
- See Also:
-
normal
Compute a normal matrix fromthis
matrix and store it intodest
.Please note that, if
this
is an orthogonal matrix or a matrix whose columns are orthogonal vectors, then this method need not be invoked, since in that casethis
itself is its normal matrix. In this case, useset(Matrix2dc)
to set a given Matrix2d to this matrix. -
getScale
Description copied from interface:Matrix2dc
Get the scaling factors ofthis
matrix for the three base axes. -
positiveX
Description copied from interface:Matrix2dc
Obtain the direction of+X
before the transformation represented bythis
matrix is applied.This method is equivalent to the following code:
Matrix2d inv = new Matrix2d(this).invert(); inv.transform(dir.set(1, 0)).normalize();
Ifthis
is already an orthogonal matrix, then consider usingMatrix2dc.normalizedPositiveX(Vector2d)
instead. -
normalizedPositiveX
Description copied from interface:Matrix2dc
Obtain the direction of+X
before the transformation represented bythis
orthogonal matrix is applied. This method only produces correct results ifthis
is an orthogonal matrix.This method is equivalent to the following code:
Matrix2d inv = new Matrix2d(this).transpose(); inv.transform(dir.set(1, 0));
- Specified by:
normalizedPositiveX
in interfaceMatrix2dc
- Parameters:
dir
- will hold the direction of+X
- Returns:
- dest
-
positiveY
Description copied from interface:Matrix2dc
Obtain the direction of+Y
before the transformation represented bythis
matrix is applied.This method is equivalent to the following code:
Matrix2d inv = new Matrix2d(this).invert(); inv.transform(dir.set(0, 1)).normalize();
Ifthis
is already an orthogonal matrix, then consider usingMatrix2dc.normalizedPositiveY(Vector2d)
instead. -
normalizedPositiveY
Description copied from interface:Matrix2dc
Obtain the direction of+Y
before the transformation represented bythis
orthogonal matrix is applied. This method only produces correct results ifthis
is an orthogonal matrix.This method is equivalent to the following code:
Matrix2d inv = new Matrix2d(this).transpose(); inv.transform(dir.set(0, 1));
- Specified by:
normalizedPositiveY
in interfaceMatrix2dc
- Parameters:
dir
- will hold the direction of+Y
- Returns:
- dest
-
hashCode
public int hashCode() -
equals
-
equals
Description copied from interface:Matrix2dc
Compare the matrix elements ofthis
matrix with the given matrix using the givendelta
and return whether all of them are equal within a maximum difference ofdelta
.Please note that this method is not used by any data structure such as
ArrayList
HashSet
orHashMap
and their operations, such asArrayList.contains(Object)
orHashSet.remove(Object)
, since those data structures only use theObject.equals(Object)
andObject.hashCode()
methods. -
swap
Exchange the values ofthis
matrix with the givenother
matrix.- Parameters:
other
- the other matrix to exchange the values with- Returns:
- this
-
add
Component-wise addthis
andother
.- Parameters:
other
- the other addend- Returns:
- this
-
add
Description copied from interface:Matrix2dc
Component-wise addthis
andother
and store the result indest
. -
sub
Component-wise subtractsubtrahend
fromthis
.- Parameters:
subtrahend
- the subtrahend- Returns:
- this
-
sub
Description copied from interface:Matrix2dc
Component-wise subtractsubtrahend
fromthis
and store the result indest
. -
mulComponentWise
Component-wise multiplythis
byother
.- Parameters:
other
- the other matrix- Returns:
- this
-
mulComponentWise
Description copied from interface:Matrix2dc
Component-wise multiplythis
byother
and store the result indest
.- Specified by:
mulComponentWise
in interfaceMatrix2dc
- Parameters:
other
- the other matrixdest
- will hold the result- Returns:
- dest
-
lerp
Linearly interpolatethis
andother
using the given interpolation factort
and store the result inthis
.If
t
is0.0
then the result isthis
. If the interpolation factor is1.0
then the result isother
.- Parameters:
other
- the other matrixt
- the interpolation factor between 0.0 and 1.0- Returns:
- this
-
lerp
Description copied from interface:Matrix2dc
Linearly interpolatethis
andother
using the given interpolation factort
and store the result indest
.If
t
is0.0
then the result isthis
. If the interpolation factor is1.0
then the result isother
. -
isFinite
public boolean isFinite()Description copied from interface:Matrix2dc
-
clone
- Overrides:
clone
in classObject
- Throws:
CloneNotSupportedException
-