Interface Matrix2dc
- All Known Implementing Classes:
Matrix2d
- Author:
- Joseph Burton
-
Method Summary
Modifier and TypeMethodDescriptionComponent-wise addthis
andother
and store the result indest
.double
Return the determinant of this matrix.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
.Invert thethis
matrix and store the result indest
.boolean
isFinite()
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.double
m01()
Return 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.double
m11()
Return the value of the matrix element at column 1 and row 1.Multiply this matrix by the suppliedright
matrix and store the result indest
.Multiply this matrix by the suppliedright
matrix and store the result indest
.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 indest
.Compute a normal matrix fromthis
matrix and store it intodest
.normalizedPositiveX
(Vector2d dest) Obtain the direction of+X
before the transformation represented bythis
orthogonal matrix is applied.normalizedPositiveY
(Vector2d dest) 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.Apply rotation to this matrix by rotating the given amount of radians and store the result indest
.rotateLocal
(double ang, Matrix2d dest) Pre-multiply a rotation to this matrix by rotating the given amount of radians and store the result indest
.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 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, Matrix2d dest) Pre-multiply scaling tothis
matrix by scaling the base axes by the given x and y factors and store the result indest
.Component-wise subtractsubtrahend
fromthis
and store the result indest
.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
.Transposethis
matrix and store the result indest
.
-
Method Details
-
m00
double m00()Return the value of the matrix element at column 0 and row 0.- Returns:
- the value of the matrix element
-
m01
double m01()Return the value of the matrix element at column 0 and row 1.- Returns:
- the value of the matrix element
-
m10
double m10()Return the value of the matrix element at column 1 and row 0.- Returns:
- the value of the matrix element
-
m11
double m11()Return the value of the matrix element at column 1 and row 1.- Returns:
- the value of the matrix element
-
mul
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!- Parameters:
right
- the right operand of the matrix multiplicationdest
- will hold the result- Returns:
- dest
-
mul
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!- Parameters:
right
- the right operand of the matrix multiplicationdest
- will hold the result- Returns:
- dest
-
mulLocal
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!- Parameters:
left
- the left operand of the matrix multiplicationdest
- the destination matrix, which will hold the result- Returns:
- dest
-
determinant
double determinant()Return the determinant of this matrix.- Returns:
- the determinant
-
invert
Invert thethis
matrix and store the result indest
.- Parameters:
dest
- will hold the result- Returns:
- dest
-
transpose
Transposethis
matrix and store the result indest
.- Parameters:
dest
- will hold the result- Returns:
- dest
-
get
Get the current values ofthis
matrix and store them intodest
.- Parameters:
dest
- the destination matrix- Returns:
- the passed in destination
-
get
Get the current values ofthis
matrix and store them as the rotational component ofdest
. All other values ofdest
will be set to 0.- Parameters:
dest
- the destination matrix- Returns:
- the passed in destination
- See Also:
-
get
Get the current values ofthis
matrix and store them as the rotational component ofdest
. All other values ofdest
will be set to identity.- Parameters:
dest
- the destination matrix- Returns:
- the passed in destination
- See Also:
-
getRotation
double getRotation()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)
.- Returns:
- the angle
-
get
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
get(int, DoubleBuffer)
, taking the absolute position as parameter.- Parameters:
buffer
- will receive the values of this matrix in column-major order at its current position- Returns:
- the passed in buffer
- See Also:
-
get
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.
- Parameters:
index
- the absolute position into the DoubleBufferbuffer
- will receive the values of this matrix in column-major order- Returns:
- the passed in buffer
-
get
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
get(int, ByteBuffer)
, taking the absolute position as parameter.- Parameters:
buffer
- will receive the values of this matrix in column-major order at its current position- Returns:
- the passed in buffer
- See Also:
-
get
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.
- Parameters:
index
- the absolute position into the ByteBufferbuffer
- will receive the values of this matrix in column-major order- Returns:
- the passed in buffer
-
getFloats
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
getFloats(int, ByteBuffer)
, taking the absolute position as parameter.- Parameters:
buffer
- will receive the elements of this matrix as float values in column-major order at its current position- Returns:
- the passed in buffer
- See Also:
-
getFloats
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.
- Parameters:
index
- the absolute position into the ByteBufferbuffer
- will receive the elements of this matrix as float values in column-major order- Returns:
- the passed in buffer
-
getTransposed
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
getTransposed(int, DoubleBuffer)
, taking the absolute position as parameter.- 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
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.
- 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
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
getTransposed(int, ByteBuffer)
, taking the absolute position as parameter.- 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
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.
- Parameters:
index
- the absolute position into the ByteBufferbuffer
- will receive the values of this matrix in row-major order- Returns:
- the passed in buffer
-
getTransposed
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
getTransposed(int, FloatBuffer)
, taking the absolute position as parameter.- 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
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.
- Parameters:
index
- the absolute position into the FloatBufferbuffer
- will receive the values of this matrix in row-major order- Returns:
- the passed in buffer
-
getTransposedFloats
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
getTransposedFloats(int, ByteBuffer)
, taking the absolute position as parameter.- 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
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.
- 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
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.
- Parameters:
address
- the off-heap address where to store this matrix- Returns:
- this
-
get
double[] get(double[] arr, int offset) Store this matrix into the supplied double array in column-major order at the given offset.- Parameters:
arr
- the array to write the matrix values intooffset
- the offset into the array- Returns:
- the passed in array
-
get
double[] get(double[] arr) 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
get(double[], int)
.- Parameters:
arr
- the array to write the matrix values into- Returns:
- the passed in array
- See Also:
-
scale
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!- Parameters:
xy
- the factors of the x and y component, respectivelydest
- will hold the result- Returns:
- dest
-
scale
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!- Parameters:
x
- the factor of the x componenty
- the factor of the y componentdest
- will hold the result- Returns:
- dest
-
scale
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!- Parameters:
xy
- the factor for all componentsdest
- will hold the result- Returns:
- dest
- See Also:
-
scaleLocal
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!- Parameters:
x
- the factor of the x componenty
- the factor of the y componentdest
- will hold the result- Returns:
- dest
-
transform
Transform the given vector by this matrix.- Parameters:
v
- the vector to transform- Returns:
- v
-
transform
Transform the given vector by this matrix and store the result indest
.- Parameters:
v
- the vector to transformdest
- will hold the result- Returns:
- dest
-
transform
Transform the vector(x, y)
by this matrix and store the result indest
.- Parameters:
x
- the x coordinate of the vector to transformy
- the y coordinate of the vector to transformdest
- will hold the result- Returns:
- dest
-
transformTranspose
Transform the given vector by the transpose of this matrix.- Parameters:
v
- the vector to transform- Returns:
- v
-
transformTranspose
Transform the given vector by the transpose of this matrix and store the result indest
.- Parameters:
v
- the vector to transformdest
- will hold the result- Returns:
- dest
-
transformTranspose
Transform the vector(x, y)
by the transpose of this matrix and store the result indest
.- Parameters:
x
- the x coordinate of the vector to transformy
- the y coordinate of the vector to transformdest
- will hold the result- Returns:
- dest
-
rotate
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
- Parameters:
ang
- the angle in radiansdest
- will hold the result- Returns:
- dest
-
rotateLocal
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
- Parameters:
ang
- the angle in radiansdest
- will hold the result- Returns:
- dest
-
getRow
Get the row at the givenrow
index, starting with0
.- 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]
-
getColumn
Get the column at the givencolumn
index, starting with0
.- 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]
-
get
double get(int column, int row) Get the matrix element value at the given column and row.- Parameters:
column
- the colum index in[0..1]
row
- the row index in[0..1]
- Returns:
- the element value
-
normal
Compute a normal matrix fromthis
matrix and store it intodest
.- Parameters:
dest
- will hold the result- Returns:
- dest
-
getScale
Get the scaling factors ofthis
matrix for the three base axes.- Parameters:
dest
- will hold the scaling factors forx
andy
- Returns:
- dest
-
positiveX
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 usingnormalizedPositiveX(Vector2d)
instead.- Parameters:
dest
- will hold the direction of+X
- Returns:
- dest
-
normalizedPositiveX
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));
- Parameters:
dest
- will hold the direction of+X
- Returns:
- dest
-
positiveY
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 usingnormalizedPositiveY(Vector2d)
instead.- Parameters:
dest
- will hold the direction of+Y
- Returns:
- dest
-
normalizedPositiveY
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));
- Parameters:
dest
- will hold the direction of+Y
- Returns:
- dest
-
add
Component-wise addthis
andother
and store the result indest
.- Parameters:
other
- the other addenddest
- will hold the result- Returns:
- dest
-
sub
Component-wise subtractsubtrahend
fromthis
and store the result indest
.- Parameters:
subtrahend
- the subtrahenddest
- will hold the result- Returns:
- dest
-
mulComponentWise
Component-wise multiplythis
byother
and store the result indest
.- Parameters:
other
- the other matrixdest
- will hold the result- Returns:
- dest
-
lerp
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
.- Parameters:
other
- the other matrixt
- the interpolation factor between 0.0 and 1.0dest
- will hold the result- Returns:
- dest
-
equals
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.- Parameters:
m
- the other matrixdelta
- the allowed maximum difference- Returns:
true
whether all of the matrix elements are equal;false
otherwise
-
isFinite
boolean isFinite()Determine whether all matrix elements are finite floating-point values, that is, they are notNaN
and notinfinity
.- Returns:
true
if all components are finite floating-point values;false
otherwise
-