Package org.joml

Class Matrix2d

  • All Implemented Interfaces:
    java.io.Externalizable, java.io.Serializable, java.lang.Cloneable, Matrix2dc

    public class Matrix2d
    extends java.lang.Object
    implements java.io.Externalizable, java.lang.Cloneable, Matrix2dc
    Contains the definition of a 2x2 matrix of doubles, and associated functions to transform it. The matrix is column-major to match OpenGL's interpretation, and it looks like this:

    m00 m10
    m01 m11

    Author:
    Joseph Burton
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      double m00  
      double m01  
      double m10  
      double m11  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Matrix2d add​(Matrix2dc other)
      Component-wise add this and other.
      Matrix2d add​(Matrix2dc other, Matrix2d dest)
      Component-wise add this and other and store the result in dest.
      java.lang.Object clone()  
      double determinant()
      Return the determinant of this matrix.
      boolean equals​(java.lang.Object obj)  
      boolean equals​(Matrix2dc m, double delta)
      Compare the matrix elements of this matrix with the given matrix using the given delta and return whether all of them are equal within a maximum difference of delta.
      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.
      java.nio.ByteBuffer get​(int index, java.nio.ByteBuffer buffer)
      Store this matrix in column-major order into the supplied ByteBuffer starting at the specified absolute buffer position/index.
      java.nio.DoubleBuffer get​(int index, java.nio.DoubleBuffer buffer)
      Store this matrix in column-major order into the supplied DoubleBuffer starting at the specified absolute buffer position/index.
      java.nio.ByteBuffer get​(java.nio.ByteBuffer buffer)
      Store this matrix in column-major order into the supplied ByteBuffer at the current buffer position.
      java.nio.DoubleBuffer get​(java.nio.DoubleBuffer buffer)
      Store this matrix in column-major order into the supplied DoubleBuffer at the current buffer position.
      Matrix2d get​(Matrix2d dest)
      Get the current values of this matrix and store them into dest.
      Matrix3d get​(Matrix3d dest)
      Get the current values of this matrix and store them as the rotational component of dest.
      Matrix3x2d get​(Matrix3x2d dest)
      Get the current values of this matrix and store them as the rotational component of dest.
      Vector2d getColumn​(int column, Vector2d dest)
      Get the column at the given column index, starting with 0.
      java.nio.ByteBuffer getFloats​(int index, java.nio.ByteBuffer buffer)
      Store the elements of this matrix as float values in column-major order into the supplied ByteBuffer starting at the specified absolute buffer position/index.
      java.nio.ByteBuffer getFloats​(java.nio.ByteBuffer buffer)
      Store the elements of this matrix as float values in column-major order into the supplied ByteBuffer at the current buffer position.
      double getRotation()
      Get the angle of the rotation component of this matrix.
      Vector2d getRow​(int row, Vector2d dest)
      Get the row at the given row index, starting with 0.
      Vector2d getScale​(Vector2d dest)
      Get the scaling factors of this matrix for the three base axes.
      Matrix2dc getToAddress​(long address)
      Store this matrix in column-major order at the given off-heap address.
      java.nio.ByteBuffer getTransposed​(int index, java.nio.ByteBuffer buffer)
      Store this matrix in row-major order into the supplied ByteBuffer starting at the specified absolute buffer position/index.
      java.nio.DoubleBuffer getTransposed​(int index, java.nio.DoubleBuffer buffer)
      Store this matrix in row-major order into the supplied DoubleBuffer starting at the specified absolute buffer position/index.
      java.nio.FloatBuffer getTransposed​(int index, java.nio.FloatBuffer buffer)
      Store this matrix in row-major order into the supplied FloatBuffer starting at the specified absolute buffer position/index.
      java.nio.ByteBuffer getTransposed​(java.nio.ByteBuffer buffer)
      Store this matrix in row-major order into the supplied ByteBuffer at the current buffer position.
      java.nio.DoubleBuffer getTransposed​(java.nio.DoubleBuffer buffer)
      Store this matrix in row-major order into the supplied DoubleBuffer at the current buffer position.
      java.nio.FloatBuffer getTransposed​(java.nio.FloatBuffer buffer)
      Store this matrix in row-major order into the supplied FloatBuffer at the current buffer position.
      java.nio.ByteBuffer getTransposedFloats​(int index, java.nio.ByteBuffer buffer)
      Store this matrix in row-major order into the supplied ByteBuffer starting at the specified absolute buffer position/index.
      java.nio.ByteBuffer getTransposedFloats​(java.nio.ByteBuffer buffer)
      Store this matrix as float values in row-major order into the supplied ByteBuffer at the current buffer position.
      int hashCode()  
      Matrix2d identity()
      Set this matrix to the identity.
      Matrix2d invert()
      Invert this matrix.
      Matrix2d invert​(Matrix2d dest)
      Invert the this matrix and store the result in dest.
      boolean isFinite()
      Determine whether all matrix elements are finite floating-point values, that is, they are not NaN and not infinity.
      Matrix2d lerp​(Matrix2dc other, double t)
      Linearly interpolate this and other using the given interpolation factor t and store the result in this.
      Matrix2d lerp​(Matrix2dc other, double t, Matrix2d dest)
      Linearly interpolate this and other using the given interpolation factor t and store the result in dest.
      double m00()
      Return the value of the matrix element at column 0 and row 0.
      Matrix2d 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.
      Matrix2d 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.
      Matrix2d 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.
      Matrix2d m11​(double m11)
      Set the value of the matrix element at column 1 and row 1.
      Matrix2d mul​(Matrix2dc right)
      Multiply this matrix by the supplied right matrix.
      Matrix2d mul​(Matrix2dc right, Matrix2d dest)
      Multiply this matrix by the supplied right matrix and store the result in dest.
      Matrix2d mul​(Matrix2fc right)
      Multiply this matrix by the supplied right matrix.
      Matrix2d mul​(Matrix2fc right, Matrix2d dest)
      Multiply this matrix by the supplied right matrix and store the result in dest.
      Matrix2d mulComponentWise​(Matrix2dc other)
      Component-wise multiply this by other.
      Matrix2d mulComponentWise​(Matrix2dc other, Matrix2d dest)
      Component-wise multiply this by other and store the result in dest.
      Matrix2d mulLocal​(Matrix2dc left)
      Pre-multiply this matrix by the supplied left matrix and store the result in this.
      Matrix2d mulLocal​(Matrix2dc left, Matrix2d dest)
      Pre-multiply this matrix by the supplied left matrix and store the result in dest.
      Matrix2d normal()
      Set this matrix to its own normal matrix.
      Matrix2d normal​(Matrix2d dest)
      Compute a normal matrix from this matrix and store it into dest.
      Vector2d normalizedPositiveX​(Vector2d dir)
      Obtain the direction of +X before the transformation represented by this orthogonal matrix is applied.
      Vector2d normalizedPositiveY​(Vector2d dir)
      Obtain the direction of +Y before the transformation represented by this orthogonal matrix is applied.
      Vector2d positiveX​(Vector2d dir)
      Obtain the direction of +X before the transformation represented by this matrix is applied.
      Vector2d positiveY​(Vector2d dir)
      Obtain the direction of +Y before the transformation represented by this matrix is applied.
      void readExternal​(java.io.ObjectInput in)  
      Matrix2d rotate​(double angle)
      Apply rotation about the origin to this matrix by rotating the given amount of radians.
      Matrix2d rotate​(double angle, Matrix2d dest)
      Apply rotation to this matrix by rotating the given amount of radians and store the result in dest.
      Matrix2d rotateLocal​(double angle)
      Pre-multiply a rotation to this matrix by rotating the given amount of radians about the origin.
      Matrix2d rotateLocal​(double angle, Matrix2d dest)
      Pre-multiply a rotation to this matrix by rotating the given amount of radians and store the result in dest.
      Matrix2d rotation​(double angle)
      Set this matrix to a rotation matrix which rotates the given radians about the origin.
      Matrix2d scale​(double xy)
      Apply scaling to this matrix by uniformly scaling all base axes by the given xy factor.
      Matrix2d scale​(double x, double y)
      Apply scaling to this matrix by scaling the base axes by the given x and y factors.
      Matrix2d scale​(double x, double y, Matrix2d dest)
      Apply scaling to this matrix by scaling the base axes by the given x and y factors and store the result in dest.
      Matrix2d scale​(double xy, Matrix2d dest)
      Apply scaling to this matrix by uniformly scaling all base axes by the given xy factor and store the result in dest.
      Matrix2d scale​(Vector2dc xy)
      Apply scaling to this matrix by scaling the base axes by the given xy.x and xy.y factors, respectively.
      Matrix2d scale​(Vector2dc xy, Matrix2d dest)
      Apply scaling to this matrix by scaling the base axes by the given xy.x and xy.y factors, respectively and store the result in dest.
      Matrix2d scaleLocal​(double x, double y)
      Pre-multiply scaling to this matrix by scaling the base axes by the given x and y factors.
      Matrix2d scaleLocal​(double x, double y, Matrix2d dest)
      Pre-multiply scaling to this matrix by scaling the base axes by the given x and y factors and store the result in dest.
      Matrix2d scaling​(double factor)
      Set this matrix to be a simple scale matrix, which scales all axes uniformly by the given factor.
      Matrix2d scaling​(double x, double y)
      Set this matrix to be a simple scale matrix.
      Matrix2d scaling​(Vector2dc xy)
      Set this matrix to be a simple scale matrix which scales the base axes by xy.x and xy.y respectively.
      Matrix2d set​(double[] m)
      Set the values in this matrix based on the supplied double array.
      Matrix2d set​(double m00, double m01, double m10, double m11)
      Set the values within this matrix to the supplied double values.
      Matrix2d set​(int column, int row, double value)
      Set the matrix element at the given column and row to the specified value.
      Matrix2d set​(int index, java.nio.ByteBuffer buffer)
      Set the values of this matrix by reading 4 double values from the given ByteBuffer in column-major order, starting at the specified absolute buffer position/index.
      Matrix2d set​(int index, java.nio.DoubleBuffer buffer)
      Set the values of this matrix by reading 4 double values from the given DoubleBuffer in column-major order, starting at the specified absolute buffer position/index.
      Matrix2d set​(java.nio.ByteBuffer buffer)
      Set the values of this matrix by reading 4 double values from the given ByteBuffer in column-major order, starting at its current position.
      Matrix2d set​(java.nio.DoubleBuffer buffer)
      Set the values of this matrix by reading 4 double values from the given DoubleBuffer in column-major order, starting at its current position.
      Matrix2d set​(Matrix2dc m)
      Set the elements of this matrix to the ones in m.
      Matrix2d set​(Matrix2fc m)
      Set the elements of this matrix to the ones in m.
      Matrix2d set​(Matrix3dc m)
      Set the elements of this matrix to the upper left 2x2 of the given Matrix3dc.
      Matrix2d set​(Matrix3fc m)
      Set the elements of this matrix to the upper left 2x2 of the given Matrix3dc.
      Matrix2d set​(Matrix3x2dc m)
      Set the elements of this matrix to the left 2x2 submatrix of m.
      Matrix2d set​(Matrix3x2fc m)
      Set the elements of this matrix to the left 2x2 submatrix of m.
      Matrix2d set​(Vector2dc col0, Vector2dc col1)
      Set the two columns of this matrix to the supplied vectors, respectively.
      Matrix2d setColumn​(int column, double x, double y)
      Set the column at the given column index, starting with 0.
      Matrix2d setColumn​(int column, Vector2dc src)
      Set the column at the given column index, starting with 0.
      Matrix2d 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.
      Matrix2d setRow​(int row, double x, double y)
      Set the row at the given row index, starting with 0.
      Matrix2d setRow​(int row, Vector2dc src)
      Set the row at the given row index, starting with 0.
      Matrix2d sub​(Matrix2dc subtrahend)
      Component-wise subtract subtrahend from this.
      Matrix2d sub​(Matrix2dc other, Matrix2d dest)
      Component-wise subtract subtrahend from this and store the result in dest.
      Matrix2d swap​(Matrix2d other)
      Exchange the values of this matrix with the given other matrix.
      java.lang.String toString()
      Return a string representation of this matrix.
      java.lang.String toString​(java.text.NumberFormat formatter)
      Return a string representation of this matrix by formatting the matrix elements with the given NumberFormat.
      Vector2d transform​(double x, double y, Vector2d dest)
      Transform the vector (x, y) by this matrix and store the result in dest.
      Vector2d transform​(Vector2d v)
      Transform the given vector by this matrix.
      Vector2d transform​(Vector2dc v, Vector2d dest)
      Transform the given vector by this matrix and store the result in dest.
      Vector2d transformTranspose​(double x, double y, Vector2d dest)
      Transform the vector (x, y) by the transpose of this matrix and store the result in dest.
      Vector2d transformTranspose​(Vector2d v)
      Transform the given vector by the transpose of this matrix.
      Vector2d transformTranspose​(Vector2dc v, Vector2d dest)
      Transform the given vector by the transpose of this matrix and store the result in dest.
      Matrix2d transpose()
      Transpose this matrix.
      Matrix2d transpose​(Matrix2d dest)
      Transpose this matrix and store the result in dest.
      void writeExternal​(java.io.ObjectOutput out)  
      Matrix2d zero()
      Set all values within this matrix to zero.
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • m00

        public double m00
      • m01

        public double m01
      • m10

        public double m10
      • m11

        public double m11
    • Constructor Detail

      • Matrix2d

        public Matrix2d​(Matrix2dc mat)
        Create a new Matrix2d and make it a copy of the given matrix.
        Parameters:
        mat - the Matrix2dc to copy the values from
      • Matrix2d

        public Matrix2d​(Matrix2fc mat)
        Create a new Matrix2d and initialize it with the values from the given matrix.
        Parameters:
        mat - the matrix to initialize this matrix with
      • Matrix2d

        public Matrix2d​(Matrix3dc mat)
        Create a new Matrix2d and make it a copy of the upper left 2x2 of the given Matrix3dc.
        Parameters:
        mat - the Matrix3dc to copy the values from
      • Matrix2d

        public Matrix2d​(Matrix3fc mat)
        Create a new Matrix2d and make it a copy of the upper left 2x2 of the given Matrix3fc.
        Parameters:
        mat - the Matrix3fc 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 m00
        m01 - the value of m01
        m10 - the value of m10
        m11 - the value of m11
      • Matrix2d

        public Matrix2d​(java.nio.DoubleBuffer buffer)
        Create a new Matrix2d by reading its 4 double components from the given DoubleBuffer 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 - the DoubleBuffer to read the matrix values from
      • Matrix2d

        public Matrix2d​(Vector2dc col0,
                        Vector2dc col1)
        Create a new Matrix2d and initialize its two columns using the supplied vectors.
        Parameters:
        col0 - the first column
        col1 - the second column
    • Method Detail

      • m00

        public double m00()
        Description copied from interface: Matrix2dc
        Return the value of the matrix element at column 0 and row 0.
        Specified by:
        m00 in interface Matrix2dc
        Returns:
        the value of the matrix element
      • m01

        public double m01()
        Description copied from interface: Matrix2dc
        Return the value of the matrix element at column 0 and row 1.
        Specified by:
        m01 in interface Matrix2dc
        Returns:
        the value of the matrix element
      • m10

        public double m10()
        Description copied from interface: Matrix2dc
        Return the value of the matrix element at column 1 and row 0.
        Specified by:
        m10 in interface Matrix2dc
        Returns:
        the value of the matrix element
      • m11

        public double m11()
        Description copied from interface: Matrix2dc
        Return the value of the matrix element at column 1 and row 1.
        Specified by:
        m11 in interface Matrix2dc
        Returns:
        the value of the matrix element
      • m00

        public Matrix2d m00​(double m00)
        Set the value of the matrix element at column 0 and row 0.
        Parameters:
        m00 - the new value
        Returns:
        this
      • m01

        public Matrix2d m01​(double m01)
        Set the value of the matrix element at column 0 and row 1.
        Parameters:
        m01 - the new value
        Returns:
        this
      • m10

        public Matrix2d m10​(double m10)
        Set the value of the matrix element at column 1 and row 0.
        Parameters:
        m10 - the new value
        Returns:
        this
      • m11

        public Matrix2d m11​(double m11)
        Set the value of the matrix element at column 1 and row 1.
        Parameters:
        m11 - the new value
        Returns:
        this
      • set

        public Matrix2d set​(Matrix2dc m)
        Set the elements of this matrix to the ones in m.
        Parameters:
        m - the matrix to copy the elements from
        Returns:
        this
      • set

        public Matrix2d set​(Matrix2fc m)
        Set the elements of this matrix to the ones in m.
        Parameters:
        m - the matrix to copy the elements from
        Returns:
        this
      • set

        public Matrix2d set​(Matrix3x2dc m)
        Set the elements of this matrix to the left 2x2 submatrix of m.
        Parameters:
        m - the matrix to copy the elements from
        Returns:
        this
      • set

        public Matrix2d set​(Matrix3x2fc m)
        Set the elements of this matrix to the left 2x2 submatrix of m.
        Parameters:
        m - the matrix to copy the elements from
        Returns:
        this
      • set

        public Matrix2d set​(Matrix3dc m)
        Set the elements of this matrix to the upper left 2x2 of the given Matrix3dc.
        Parameters:
        m - the Matrix3dc to copy the values from
        Returns:
        this
      • set

        public Matrix2d set​(Matrix3fc m)
        Set the elements of this matrix to the upper left 2x2 of the given Matrix3dc.
        Parameters:
        m - the Matrix3fc to copy the values from
        Returns:
        this
      • mul

        public Matrix2d mul​(Matrix2dc right)
        Multiply this matrix by the supplied right matrix.

        If M is this matrix and R the right matrix, then the new matrix will be M * R. So when transforming a vector v with the new matrix by using M * R * v, the transformation of the right matrix will be applied first!

        Parameters:
        right - the right operand of the matrix multiplication
        Returns:
        this
      • mul

        public Matrix2d mul​(Matrix2dc right,
                            Matrix2d dest)
        Description copied from interface: Matrix2dc
        Multiply this matrix by the supplied right matrix and store the result in dest.

        If M is this matrix and R the right matrix, then the new matrix will be M * R. So when transforming a vector v with the new matrix by using M * R * v, the transformation of the right matrix will be applied first!

        Specified by:
        mul in interface Matrix2dc
        Parameters:
        right - the right operand of the matrix multiplication
        dest - will hold the result
        Returns:
        dest
      • mul

        public Matrix2d mul​(Matrix2fc right)
        Multiply this matrix by the supplied right matrix.

        If M is this matrix and R the right matrix, then the new matrix will be M * R. So when transforming a vector v with the new matrix by using M * R * v, the transformation of the right matrix will be applied first!

        Parameters:
        right - the right operand of the matrix multiplication
        Returns:
        this
      • mul

        public Matrix2d mul​(Matrix2fc right,
                            Matrix2d dest)
        Description copied from interface: Matrix2dc
        Multiply this matrix by the supplied right matrix and store the result in dest.

        If M is this matrix and R the right matrix, then the new matrix will be M * R. So when transforming a vector v with the new matrix by using M * R * v, the transformation of the right matrix will be applied first!

        Specified by:
        mul in interface Matrix2dc
        Parameters:
        right - the right operand of the matrix multiplication
        dest - will hold the result
        Returns:
        dest
      • mulLocal

        public Matrix2d mulLocal​(Matrix2dc left)
        Pre-multiply this matrix by the supplied left matrix and store the result in this.

        If M is this matrix and L the left matrix, then the new matrix will be L * M. So when transforming a vector v with the new matrix by using L * M * v, the transformation of this matrix will be applied first!

        Parameters:
        left - the left operand of the matrix multiplication
        Returns:
        this
      • mulLocal

        public Matrix2d mulLocal​(Matrix2dc left,
                                 Matrix2d dest)
        Description copied from interface: Matrix2dc
        Pre-multiply this matrix by the supplied left matrix and store the result in dest.

        If M is this matrix and L the left matrix, then the new matrix will be L * M. So when transforming a vector v with the new matrix by using L * M * v, the transformation of this matrix will be applied first!

        Specified by:
        mulLocal in interface Matrix2dc
        Parameters:
        left - the left operand of the matrix multiplication
        dest - the destination matrix, which will hold the result
        Returns:
        dest
      • set

        public Matrix2d set​(double m00,
                            double m01,
                            double m10,
                            double m11)
        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 m00
        m01 - the new value of m01
        m10 - the new value of m10
        m11 - the new value of m11
        Returns:
        this
      • set

        public Matrix2d set​(double[] m)
        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

        public Matrix2d set​(Vector2dc col0,
                            Vector2dc col1)
        Set the two columns of this matrix to the supplied vectors, respectively.
        Parameters:
        col0 - the first column
        col1 - the second column
        Returns:
        this
      • determinant

        public double determinant()
        Description copied from interface: Matrix2dc
        Return the determinant of this matrix.
        Specified by:
        determinant in interface Matrix2dc
        Returns:
        the determinant
      • invert

        public Matrix2d invert()
        Invert this matrix.
        Returns:
        this
      • invert

        public Matrix2d invert​(Matrix2d dest)
        Description copied from interface: Matrix2dc
        Invert the this matrix and store the result in dest.
        Specified by:
        invert in interface Matrix2dc
        Parameters:
        dest - will hold the result
        Returns:
        dest
      • transpose

        public Matrix2d transpose()
        Transpose this matrix.
        Returns:
        this
      • transpose

        public Matrix2d transpose​(Matrix2d dest)
        Description copied from interface: Matrix2dc
        Transpose this matrix and store the result in dest.
        Specified by:
        transpose in interface Matrix2dc
        Parameters:
        dest - will hold the result
        Returns:
        dest
      • toString

        public java.lang.String toString()
        Return a string representation of this matrix.

        This method creates a new DecimalFormat on every invocation with the format string "0.000E0;-".

        Overrides:
        toString in class java.lang.Object
        Returns:
        the string representation
      • toString

        public java.lang.String toString​(java.text.NumberFormat formatter)
        Return a string representation of this matrix by formatting the matrix elements with the given NumberFormat.
        Parameters:
        formatter - the NumberFormat used to format the matrix values with
        Returns:
        the string representation
      • get

        public Matrix2d get​(Matrix2d dest)
        Get the current values of this matrix and store them into dest.

        This is the reverse method of set(Matrix2dc) and allows to obtain intermediate calculation results when chaining multiple transformations.

        Specified by:
        get in interface Matrix2dc
        Parameters:
        dest - the destination matrix
        Returns:
        the passed in destination
        See Also:
        set(Matrix2dc)
      • get

        public Matrix3x2d get​(Matrix3x2d dest)
        Description copied from interface: Matrix2dc
        Get the current values of this matrix and store them as the rotational component of dest. All other values of dest will be set to 0.
        Specified by:
        get in interface Matrix2dc
        Parameters:
        dest - the destination matrix
        Returns:
        the passed in destination
        See Also:
        Matrix3x2d.set(Matrix2dc)
      • get

        public Matrix3d get​(Matrix3d dest)
        Description copied from interface: Matrix2dc
        Get the current values of this matrix and store them as the rotational component of dest. All other values of dest will be set to identity.
        Specified by:
        get in interface Matrix2dc
        Parameters:
        dest - the destination matrix
        Returns:
        the passed in destination
        See Also:
        Matrix3d.set(Matrix2dc)
      • getRotation

        public double getRotation()
        Description copied from interface: Matrix2dc
        Get the angle of the rotation component of this 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 interface Matrix2dc
        Returns:
        the angle
      • get

        public java.nio.DoubleBuffer get​(java.nio.DoubleBuffer buffer)
        Description copied from interface: Matrix2dc
        Store this matrix in column-major order into the supplied DoubleBuffer at the current buffer position.

        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.

        Specified by:
        get in interface Matrix2dc
        Parameters:
        buffer - will receive the values of this matrix in column-major order at its current position
        Returns:
        the passed in buffer
        See Also:
        Matrix2dc.get(int, DoubleBuffer)
      • get

        public java.nio.DoubleBuffer get​(int index,
                                         java.nio.DoubleBuffer buffer)
        Description copied from interface: Matrix2dc
        Store this matrix in column-major order into the supplied DoubleBuffer starting at the specified absolute buffer position/index.

        This method will not increment the position of the given DoubleBuffer.

        Specified by:
        get in interface Matrix2dc
        Parameters:
        index - the absolute position into the DoubleBuffer
        buffer - will receive the values of this matrix in column-major order
        Returns:
        the passed in buffer
      • get

        public java.nio.ByteBuffer get​(java.nio.ByteBuffer buffer)
        Description copied from interface: Matrix2dc
        Store this matrix in column-major order into the supplied ByteBuffer at the current buffer position.

        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.

        Specified by:
        get in interface Matrix2dc
        Parameters:
        buffer - will receive the values of this matrix in column-major order at its current position
        Returns:
        the passed in buffer
        See Also:
        Matrix2dc.get(int, ByteBuffer)
      • get

        public java.nio.ByteBuffer get​(int index,
                                       java.nio.ByteBuffer buffer)
        Description copied from interface: Matrix2dc
        Store this matrix in column-major order into the supplied ByteBuffer starting at the specified absolute buffer position/index.

        This method will not increment the position of the given ByteBuffer.

        Specified by:
        get in interface Matrix2dc
        Parameters:
        index - the absolute position into the ByteBuffer
        buffer - will receive the values of this matrix in column-major order
        Returns:
        the passed in buffer
      • getFloats

        public java.nio.ByteBuffer getFloats​(java.nio.ByteBuffer buffer)
        Description copied from interface: Matrix2dc
        Store the elements of this matrix as float values in column-major order into the supplied ByteBuffer at the current buffer position.

        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.

        Specified by:
        getFloats in interface Matrix2dc
        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:
        Matrix2dc.getFloats(int, ByteBuffer)
      • getFloats

        public java.nio.ByteBuffer getFloats​(int index,
                                             java.nio.ByteBuffer buffer)
        Description copied from interface: Matrix2dc
        Store the elements of this matrix as float values in column-major order into the supplied ByteBuffer 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.

        Specified by:
        getFloats in interface Matrix2dc
        Parameters:
        index - the absolute position into the ByteBuffer
        buffer - will receive the elements of this matrix as float values in column-major order
        Returns:
        the passed in buffer
      • getTransposed

        public java.nio.DoubleBuffer getTransposed​(java.nio.DoubleBuffer buffer)
        Description copied from interface: Matrix2dc
        Store this matrix in row-major order into the supplied DoubleBuffer at the current buffer position.

        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 interface Matrix2dc
        Parameters:
        buffer - will receive the values of this matrix in row-major order at its current position
        Returns:
        the passed in buffer
        See Also:
        Matrix2dc.getTransposed(int, DoubleBuffer)
      • getTransposed

        public java.nio.DoubleBuffer getTransposed​(int index,
                                                   java.nio.DoubleBuffer buffer)
        Description copied from interface: Matrix2dc
        Store this matrix in row-major order into the supplied DoubleBuffer starting at the specified absolute buffer position/index.

        This method will not increment the position of the given DoubleBuffer.

        Specified by:
        getTransposed in interface Matrix2dc
        Parameters:
        index - the absolute position into the DoubleBuffer
        buffer - will receive the values of this matrix in row-major order
        Returns:
        the passed in buffer
      • getTransposed

        public java.nio.FloatBuffer getTransposed​(java.nio.FloatBuffer buffer)
        Description copied from interface: Matrix2dc
        Store this matrix in row-major order into the supplied FloatBuffer at the current buffer position.

        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 interface Matrix2dc
        Parameters:
        buffer - will receive the values of this matrix in row-major order at its current position
        Returns:
        the passed in buffer
        See Also:
        Matrix2dc.getTransposed(int, FloatBuffer)
      • getTransposed

        public java.nio.FloatBuffer getTransposed​(int index,
                                                  java.nio.FloatBuffer buffer)
        Description copied from interface: Matrix2dc
        Store this matrix in row-major order into the supplied FloatBuffer 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 interface Matrix2dc
        Parameters:
        index - the absolute position into the FloatBuffer
        buffer - will receive the values of this matrix in row-major order
        Returns:
        the passed in buffer
      • getTransposed

        public java.nio.ByteBuffer getTransposed​(java.nio.ByteBuffer buffer)
        Description copied from interface: Matrix2dc
        Store this matrix in row-major order into the supplied ByteBuffer at the current buffer position.

        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 interface Matrix2dc
        Parameters:
        buffer - will receive the values of this matrix in row-major order at its current position
        Returns:
        the passed in buffer
        See Also:
        Matrix2dc.getTransposed(int, ByteBuffer)
      • getTransposed

        public java.nio.ByteBuffer getTransposed​(int index,
                                                 java.nio.ByteBuffer buffer)
        Description copied from interface: Matrix2dc
        Store this matrix in row-major order into the supplied ByteBuffer starting at the specified absolute buffer position/index.

        This method will not increment the position of the given ByteBuffer.

        Specified by:
        getTransposed in interface Matrix2dc
        Parameters:
        index - the absolute position into the ByteBuffer
        buffer - will receive the values of this matrix in row-major order
        Returns:
        the passed in buffer
      • getTransposedFloats

        public java.nio.ByteBuffer getTransposedFloats​(java.nio.ByteBuffer buffer)
        Description copied from interface: Matrix2dc
        Store this matrix as float values in row-major order into the supplied ByteBuffer at the current buffer position.

        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 interface Matrix2dc
        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:
        Matrix2dc.getTransposedFloats(int, ByteBuffer)
      • getTransposedFloats

        public java.nio.ByteBuffer getTransposedFloats​(int index,
                                                       java.nio.ByteBuffer buffer)
        Description copied from interface: Matrix2dc
        Store this matrix in row-major order into the supplied ByteBuffer 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 interface Matrix2dc
        Parameters:
        index - the absolute position into the ByteBuffer
        buffer - will receive the values of this matrix as float values in row-major order
        Returns:
        the passed in buffer
      • getToAddress

        public Matrix2dc getToAddress​(long address)
        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 interface Matrix2dc
        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.
        Specified by:
        get in interface Matrix2dc
        Parameters:
        arr - the array to write the matrix values into
        offset - the offset into the array
        Returns:
        the passed in array
      • 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).

        Specified by:
        get in interface Matrix2dc
        Parameters:
        arr - the array to write the matrix values into
        Returns:
        the passed in array
        See Also:
        Matrix2dc.get(double[], int)
      • set

        public Matrix2d set​(java.nio.DoubleBuffer buffer)
        Set the values of this matrix by reading 4 double values from the given DoubleBuffer 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

        public Matrix2d set​(java.nio.ByteBuffer buffer)
        Set the values of this matrix by reading 4 double values from the given ByteBuffer 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

        public Matrix2d set​(int index,
                            java.nio.DoubleBuffer buffer)
        Set the values of this matrix by reading 4 double values from the given DoubleBuffer 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 DoubleBuffer
        buffer - the DoubleBuffer to read the matrix values from in column-major order
        Returns:
        this
      • set

        public Matrix2d set​(int index,
                            java.nio.ByteBuffer buffer)
        Set the values of this matrix by reading 4 double values from the given ByteBuffer 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 ByteBuffer
        buffer - the ByteBuffer to read the matrix values from in column-major order
        Returns:
        this
      • setFromAddress

        public Matrix2d 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.

        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

        public Matrix2d zero()
        Set all values within this matrix to zero.
        Returns:
        this
      • identity

        public Matrix2d identity()
        Set this matrix to the identity.
        Returns:
        this
      • scale

        public Matrix2d scale​(Vector2dc xy,
                              Matrix2d dest)
        Description copied from interface: Matrix2dc
        Apply scaling to this matrix by scaling the base axes by the given xy.x and xy.y factors, respectively and store the result in dest.

        If M is this matrix and S the scaling matrix, then the new matrix will be M * S. So when transforming a vector v with the new matrix by using M * S * v , the scaling will be applied first!

        Specified by:
        scale in interface Matrix2dc
        Parameters:
        xy - the factors of the x and y component, respectively
        dest - will hold the result
        Returns:
        dest
      • scale

        public Matrix2d scale​(Vector2dc xy)
        Apply scaling to this matrix by scaling the base axes by the given xy.x and xy.y factors, respectively.

        If M is this matrix and S the scaling matrix, then the new matrix will be M * S. So when transforming a vector v with the new matrix by using M * S * v, the scaling will be applied first!

        Parameters:
        xy - the factors of the x and y component, respectively
        Returns:
        this
      • scale

        public Matrix2d scale​(double x,
                              double y,
                              Matrix2d dest)
        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 in dest.

        If M is this matrix and S the scaling matrix, then the new matrix will be M * S. So when transforming a vector v with the new matrix by using M * S * v , the scaling will be applied first!

        Specified by:
        scale in interface Matrix2dc
        Parameters:
        x - the factor of the x component
        y - the factor of the y component
        dest - will hold the result
        Returns:
        dest
      • scale

        public Matrix2d scale​(double x,
                              double y)
        Apply scaling to this matrix by scaling the base axes by the given x and y factors.

        If M is this matrix and S the scaling matrix, then the new matrix will be M * S. So when transforming a vector v with the new matrix by using M * S * v , the scaling will be applied first!

        Parameters:
        x - the factor of the x component
        y - the factor of the y component
        Returns:
        this
      • scale

        public Matrix2d scale​(double xy,
                              Matrix2d dest)
        Description copied from interface: Matrix2dc
        Apply scaling to this matrix by uniformly scaling all base axes by the given xy factor and store the result in dest.

        If M is this matrix and S the scaling matrix, then the new matrix will be M * S. So when transforming a vector v with the new matrix by using M * S * v , the scaling will be applied first!

        Specified by:
        scale in interface Matrix2dc
        Parameters:
        xy - the factor for all components
        dest - will hold the result
        Returns:
        dest
        See Also:
        Matrix2dc.scale(double, double, Matrix2d)
      • scale

        public Matrix2d scale​(double xy)
        Apply scaling to this matrix by uniformly scaling all base axes by the given xy factor.

        If M is this matrix and S the scaling matrix, then the new matrix will be M * S. So when transforming a vector v with the new matrix by using M * S * v , the scaling will be applied first!

        Parameters:
        xy - the factor for all components
        Returns:
        this
        See Also:
        scale(double, double)
      • scaleLocal

        public Matrix2d scaleLocal​(double x,
                                   double y,
                                   Matrix2d dest)
        Description copied from interface: Matrix2dc
        Pre-multiply scaling to this matrix by scaling the base axes by the given x and y factors and store the result in dest.

        If M is this matrix and S the scaling matrix, then the new matrix will be S * M. So when transforming a vector v with the new matrix by using S * M * v , the scaling will be applied last!

        Specified by:
        scaleLocal in interface Matrix2dc
        Parameters:
        x - the factor of the x component
        y - the factor of the y component
        dest - will hold the result
        Returns:
        dest
      • scaleLocal

        public Matrix2d scaleLocal​(double x,
                                   double y)
        Pre-multiply scaling to this matrix by scaling the base axes by the given x and y factors.

        If M is this matrix and S the scaling matrix, then the new matrix will be S * M. So when transforming a vector v with the new matrix by using S * M * v, the scaling will be applied last!

        Parameters:
        x - the factor of the x component
        y - the factor of the y component
        Returns:
        this
      • scaling

        public Matrix2d scaling​(double factor)
        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:
        scale(double)
      • scaling

        public Matrix2d scaling​(double x,
                                double y)
        Set this matrix to be a simple scale matrix.
        Parameters:
        x - the scale in x
        y - the scale in y
        Returns:
        this
      • scaling

        public Matrix2d scaling​(Vector2dc xy)
        Set this matrix to be a simple scale matrix which scales the base axes by xy.x and xy.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:
        scale(Vector2dc)
      • rotation

        public Matrix2d rotation​(double angle)
        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:
        rotate(double)
      • transform

        public Vector2d transform​(Vector2d v)
        Description copied from interface: Matrix2dc
        Transform the given vector by this matrix.
        Specified by:
        transform in interface Matrix2dc
        Parameters:
        v - the vector to transform
        Returns:
        v
      • transform

        public Vector2d transform​(Vector2dc v,
                                  Vector2d dest)
        Description copied from interface: Matrix2dc
        Transform the given vector by this matrix and store the result in dest.
        Specified by:
        transform in interface Matrix2dc
        Parameters:
        v - the vector to transform
        dest - will hold the result
        Returns:
        dest
      • transform

        public Vector2d transform​(double x,
                                  double y,
                                  Vector2d dest)
        Description copied from interface: Matrix2dc
        Transform the vector (x, y) by this matrix and store the result in dest.
        Specified by:
        transform in interface Matrix2dc
        Parameters:
        x - the x coordinate of the vector to transform
        y - the y coordinate of the vector to transform
        dest - will hold the result
        Returns:
        dest
      • transformTranspose

        public Vector2d transformTranspose​(Vector2d v)
        Description copied from interface: Matrix2dc
        Transform the given vector by the transpose of this matrix.
        Specified by:
        transformTranspose in interface Matrix2dc
        Parameters:
        v - the vector to transform
        Returns:
        v
      • transformTranspose

        public Vector2d transformTranspose​(Vector2dc v,
                                           Vector2d dest)
        Description copied from interface: Matrix2dc
        Transform the given vector by the transpose of this matrix and store the result in dest.
        Specified by:
        transformTranspose in interface Matrix2dc
        Parameters:
        v - the vector to transform
        dest - will hold the result
        Returns:
        dest
      • transformTranspose

        public Vector2d transformTranspose​(double x,
                                           double y,
                                           Vector2d dest)
        Description copied from interface: Matrix2dc
        Transform the vector (x, y) by the transpose of this matrix and store the result in dest.
        Specified by:
        transformTranspose in interface Matrix2dc
        Parameters:
        x - the x coordinate of the vector to transform
        y - the y coordinate of the vector to transform
        dest - will hold the result
        Returns:
        dest
      • writeExternal

        public void writeExternal​(java.io.ObjectOutput out)
                           throws java.io.IOException
        Specified by:
        writeExternal in interface java.io.Externalizable
        Throws:
        java.io.IOException
      • readExternal

        public void readExternal​(java.io.ObjectInput in)
                          throws java.io.IOException
        Specified by:
        readExternal in interface java.io.Externalizable
        Throws:
        java.io.IOException
      • rotate

        public Matrix2d rotate​(double angle)
        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 is this matrix and R the rotation matrix, then the new matrix will be M * R. So when transforming a vector v with the new matrix by using M * R * v , the rotation will be applied first!

        Reference: http://en.wikipedia.org

        Parameters:
        angle - the angle in radians
        Returns:
        this
      • rotate

        public Matrix2d rotate​(double angle,
                               Matrix2d dest)
        Description copied from interface: Matrix2dc
        Apply rotation to this matrix by rotating the given amount of radians and store the result in dest.

        The produced rotation will rotate a vector counter-clockwise around the origin.

        If M is this matrix and R the rotation matrix, then the new matrix will be M * R. So when transforming a vector v with the new matrix by using M * R * v , the rotation will be applied first!

        Reference: http://en.wikipedia.org

        Specified by:
        rotate in interface Matrix2dc
        Parameters:
        angle - the angle in radians
        dest - will hold the result
        Returns:
        dest
      • rotateLocal

        public Matrix2d rotateLocal​(double angle)
        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 is this matrix and R the rotation matrix, then the new matrix will be R * M. So when transforming a vector v with the new matrix by using R * 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:
        rotation(double)
      • rotateLocal

        public Matrix2d rotateLocal​(double angle,
                                    Matrix2d dest)
        Description copied from interface: Matrix2dc
        Pre-multiply a rotation to this matrix by rotating the given amount of radians and store the result in dest.

        The produced rotation will rotate a vector counter-clockwise around the origin.

        If M is this matrix and R the rotation matrix, then the new matrix will be R * M. So when transforming a vector v with the new matrix by using R * M * v, the rotation will be applied last!

        Reference: http://en.wikipedia.org

        Specified by:
        rotateLocal in interface Matrix2dc
        Parameters:
        angle - the angle in radians
        dest - will hold the result
        Returns:
        dest
      • getRow

        public Vector2d getRow​(int row,
                               Vector2d dest)
                        throws java.lang.IndexOutOfBoundsException
        Description copied from interface: Matrix2dc
        Get the row at the given row index, starting with 0.
        Specified by:
        getRow in interface Matrix2dc
        Parameters:
        row - the row index in [0..1]
        dest - will hold the row components
        Returns:
        the passed in destination
        Throws:
        java.lang.IndexOutOfBoundsException - if row is not in [0..1]
      • setRow

        public Matrix2d setRow​(int row,
                               Vector2dc src)
                        throws java.lang.IndexOutOfBoundsException
        Set the row at the given row index, starting with 0.
        Parameters:
        row - the row index in [0..1]
        src - the row components to set
        Returns:
        this
        Throws:
        java.lang.IndexOutOfBoundsException - if row is not in [0..1]
      • setRow

        public Matrix2d setRow​(int row,
                               double x,
                               double y)
                        throws java.lang.IndexOutOfBoundsException
        Set the row at the given row index, starting with 0.
        Parameters:
        row - the row index in [0..1]
        x - the first element in the row
        y - the second element in the row
        Returns:
        this
        Throws:
        java.lang.IndexOutOfBoundsException - if row is not in [0..1]
      • getColumn

        public Vector2d getColumn​(int column,
                                  Vector2d dest)
                           throws java.lang.IndexOutOfBoundsException
        Description copied from interface: Matrix2dc
        Get the column at the given column index, starting with 0.
        Specified by:
        getColumn in interface Matrix2dc
        Parameters:
        column - the column index in [0..1]
        dest - will hold the column components
        Returns:
        the passed in destination
        Throws:
        java.lang.IndexOutOfBoundsException - if column is not in [0..1]
      • setColumn

        public Matrix2d setColumn​(int column,
                                  Vector2dc src)
                           throws java.lang.IndexOutOfBoundsException
        Set the column at the given column index, starting with 0.
        Parameters:
        column - the column index in [0..1]
        src - the column components to set
        Returns:
        this
        Throws:
        java.lang.IndexOutOfBoundsException - if column is not in [0..1]
      • setColumn

        public Matrix2d setColumn​(int column,
                                  double x,
                                  double y)
                           throws java.lang.IndexOutOfBoundsException
        Set the column at the given column index, starting with 0.
        Parameters:
        column - the column index in [0..1]
        x - the first element in the column
        y - the second element in the column
        Returns:
        this
        Throws:
        java.lang.IndexOutOfBoundsException - if column 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.
        Specified by:
        get in interface Matrix2dc
        Parameters:
        column - the colum index in [0..1]
        row - the row index in [0..1]
        Returns:
        the element value
      • set

        public Matrix2d set​(int column,
                            int row,
                            double value)
        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

        public Matrix2d normal()
        Set this 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 case this itself is its normal matrix. In this case, use set(Matrix2dc) to set a given Matrix2d to this matrix.

        Returns:
        this
        See Also:
        set(Matrix2dc)
      • normal

        public Matrix2d normal​(Matrix2d dest)
        Compute a normal matrix from this matrix and store it into dest.

        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 case this itself is its normal matrix. In this case, use set(Matrix2dc) to set a given Matrix2d to this matrix.

        Specified by:
        normal in interface Matrix2dc
        Parameters:
        dest - will hold the result
        Returns:
        dest
        See Also:
        set(Matrix2dc)
      • getScale

        public Vector2d getScale​(Vector2d dest)
        Description copied from interface: Matrix2dc
        Get the scaling factors of this matrix for the three base axes.
        Specified by:
        getScale in interface Matrix2dc
        Parameters:
        dest - will hold the scaling factors for x and y
        Returns:
        dest
      • positiveX

        public Vector2d positiveX​(Vector2d dir)
        Description copied from interface: Matrix2dc
        Obtain the direction of +X before the transformation represented by this matrix is applied.

        This method is equivalent to the following code:

         Matrix2d inv = new Matrix2d(this).invert();
         inv.transform(dir.set(1, 0)).normalize();
         
        If this is already an orthogonal matrix, then consider using Matrix2dc.normalizedPositiveX(Vector2d) instead.
        Specified by:
        positiveX in interface Matrix2dc
        Parameters:
        dir - will hold the direction of +X
        Returns:
        dest
      • normalizedPositiveX

        public Vector2d normalizedPositiveX​(Vector2d dir)
        Description copied from interface: Matrix2dc
        Obtain the direction of +X before the transformation represented by this orthogonal matrix is applied. This method only produces correct results if this 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 interface Matrix2dc
        Parameters:
        dir - will hold the direction of +X
        Returns:
        dest
      • positiveY

        public Vector2d positiveY​(Vector2d dir)
        Description copied from interface: Matrix2dc
        Obtain the direction of +Y before the transformation represented by this matrix is applied.

        This method is equivalent to the following code:

         Matrix2d inv = new Matrix2d(this).invert();
         inv.transform(dir.set(0, 1)).normalize();
         
        If this is already an orthogonal matrix, then consider using Matrix2dc.normalizedPositiveY(Vector2d) instead.
        Specified by:
        positiveY in interface Matrix2dc
        Parameters:
        dir - will hold the direction of +Y
        Returns:
        dest
      • normalizedPositiveY

        public Vector2d normalizedPositiveY​(Vector2d dir)
        Description copied from interface: Matrix2dc
        Obtain the direction of +Y before the transformation represented by this orthogonal matrix is applied. This method only produces correct results if this 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 interface Matrix2dc
        Parameters:
        dir - will hold the direction of +Y
        Returns:
        dest
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • equals

        public boolean equals​(Matrix2dc m,
                              double delta)
        Description copied from interface: Matrix2dc
        Compare the matrix elements of this matrix with the given matrix using the given delta and return whether all of them are equal within a maximum difference of delta.

        Please note that this method is not used by any data structure such as ArrayList HashSet or HashMap and their operations, such as ArrayList.contains(Object) or HashSet.remove(Object), since those data structures only use the Object.equals(Object) and Object.hashCode() methods.

        Specified by:
        equals in interface Matrix2dc
        Parameters:
        m - the other matrix
        delta - the allowed maximum difference
        Returns:
        true whether all of the matrix elements are equal; false otherwise
      • swap

        public Matrix2d swap​(Matrix2d other)
        Exchange the values of this matrix with the given other matrix.
        Parameters:
        other - the other matrix to exchange the values with
        Returns:
        this
      • add

        public Matrix2d add​(Matrix2dc other)
        Component-wise add this and other.
        Parameters:
        other - the other addend
        Returns:
        this
      • add

        public Matrix2d add​(Matrix2dc other,
                            Matrix2d dest)
        Description copied from interface: Matrix2dc
        Component-wise add this and other and store the result in dest.
        Specified by:
        add in interface Matrix2dc
        Parameters:
        other - the other addend
        dest - will hold the result
        Returns:
        dest
      • sub

        public Matrix2d sub​(Matrix2dc subtrahend)
        Component-wise subtract subtrahend from this.
        Parameters:
        subtrahend - the subtrahend
        Returns:
        this
      • sub

        public Matrix2d sub​(Matrix2dc other,
                            Matrix2d dest)
        Description copied from interface: Matrix2dc
        Component-wise subtract subtrahend from this and store the result in dest.
        Specified by:
        sub in interface Matrix2dc
        Parameters:
        other - the subtrahend
        dest - will hold the result
        Returns:
        dest
      • mulComponentWise

        public Matrix2d mulComponentWise​(Matrix2dc other)
        Component-wise multiply this by other.
        Parameters:
        other - the other matrix
        Returns:
        this
      • mulComponentWise

        public Matrix2d mulComponentWise​(Matrix2dc other,
                                         Matrix2d dest)
        Description copied from interface: Matrix2dc
        Component-wise multiply this by other and store the result in dest.
        Specified by:
        mulComponentWise in interface Matrix2dc
        Parameters:
        other - the other matrix
        dest - will hold the result
        Returns:
        dest
      • lerp

        public Matrix2d lerp​(Matrix2dc other,
                             double t)
        Linearly interpolate this and other using the given interpolation factor t and store the result in this.

        If t is 0.0 then the result is this. If the interpolation factor is 1.0 then the result is other.

        Parameters:
        other - the other matrix
        t - the interpolation factor between 0.0 and 1.0
        Returns:
        this
      • lerp

        public Matrix2d lerp​(Matrix2dc other,
                             double t,
                             Matrix2d dest)
        Description copied from interface: Matrix2dc
        Linearly interpolate this and other using the given interpolation factor t and store the result in dest.

        If t is 0.0 then the result is this. If the interpolation factor is 1.0 then the result is other.

        Specified by:
        lerp in interface Matrix2dc
        Parameters:
        other - the other matrix
        t - the interpolation factor between 0.0 and 1.0
        dest - will hold the result
        Returns:
        dest
      • isFinite

        public boolean isFinite()
        Description copied from interface: Matrix2dc
        Determine whether all matrix elements are finite floating-point values, that is, they are not NaN and not infinity.
        Specified by:
        isFinite in interface Matrix2dc
        Returns:
        true if all components are finite floating-point values; false otherwise
      • clone

        public java.lang.Object clone()
                               throws java.lang.CloneNotSupportedException
        Overrides:
        clone in class java.lang.Object
        Throws:
        java.lang.CloneNotSupportedException