Class Matrix3


  • public class Matrix3
    extends java.lang.Object
    3 x 3 matrix in row-major order.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      double[] m
      The matrix's components, stored in row-major order.
    • Constructor Summary

      Constructors 
      Constructor Description
      Matrix3()
      Constructs a 3 x 3 identity matrix.
      Matrix3​(double m11, double m12, double m13, double m21, double m22, double m23, double m31, double m32, double m33)
      Constructs a 3 x 3 matrix with specified components.
      Matrix3​(Matrix3 matrix)
      Constructs a 3 x 3 matrix with the components of a specified matrix.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object o)  
      int hashCode()  
      Matrix3 invert()
      Inverts this matrix in place.
      Matrix3 invertMatrix​(Matrix3 matrix)
      Inverts the specified matrix and stores the result in this matrix.
      Matrix3 multiplyByMatrix​(double m11, double m12, double m13, double m21, double m22, double m23, double m31, double m32, double m33)
      Multiplies this matrix by a matrix specified by individual components.
      Matrix3 multiplyByMatrix​(Matrix3 matrix)
      Multiplies this matrix by a specified matrix.
      Matrix3 multiplyByRotation​(double angleDegrees)
      Multiplies this matrix by a rotation matrix about a specified axis and angle.
      Matrix3 multiplyByScale​(double xScale, double yScale)
      Multiplies this matrix by a scale matrix with specified values.
      Matrix3 multiplyByTileTransform​(Sector src, Sector dst)
      Multiplies this matrix by a matrix that transforms normalized coordinates from a source sector to a destination sector.
      Matrix3 multiplyByTranslation​(double x, double y)
      Multiplies this matrix by a translation matrix with specified translation values.
      Matrix3 multiplyByVerticalFlip()
      Multiplies this matrix by a matrix that flips and shifts the y-axis.
      Matrix3 set​(double m11, double m12, double m13, double m21, double m22, double m23, double m31, double m32, double m33)
      Sets this 3 x 3 matrix to specified components.
      Matrix3 set​(Matrix3 matrix)
      Sets this 3 x 3 matrix to the components of a specified matrix.
      Matrix3 setRotation​(double angleDegrees)
      Sets the rotation components of this matrix to a specified angle.
      Matrix3 setScale​(double xScale, double yScale)
      Sets the scale components of this matrix to specified values.
      Matrix3 setToIdentity()
      Sets this matrix to the 3 x 3 identity matrix.
      Matrix3 setToMultiply​(Matrix3 a, Matrix3 b)
      Sets this matrix to the matrix product of two specified matrices.
      Matrix3 setToRotation​(double angleDegrees)
      Sets this matrix to a rotation matrix with a specified angle.
      Matrix3 setToScale​(double xScale, double yScale)
      Sets this matrix to a scale matrix with specified scale components.
      Matrix3 setToTileTransform​(Sector src, Sector dst)
      Sets this matrix to one that transforms normalized coordinates from a source sector to a destination sector.
      Matrix3 setToTranslation​(double x, double y)
      Sets this matrix to a translation matrix with specified translation components.
      Matrix3 setToVerticalFlip()
      Sets this matrix to one that flips and shifts the y-axis.
      Matrix3 setTranslation​(double x, double y)
      Sets the translation components of this matrix to specified values.
      java.lang.String toString()  
      Matrix3 transpose()
      Transposes this matrix in place.
      Matrix3 transposeMatrix​(Matrix3 matrix)
      Transposes the specified matrix and stores the result in this matrix.
      float[] transposeToArray​(float[] result, int offset)
      Transposes this matrix, storing the result in the specified single precision array.
      • Methods inherited from class java.lang.Object

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

      • m

        public final double[] m
        The matrix's components, stored in row-major order. Initialized to the 3 x 3 identity matrix.
    • Constructor Detail

      • Matrix3

        public Matrix3()
        Constructs a 3 x 3 identity matrix.
      • Matrix3

        public Matrix3​(double m11,
                       double m12,
                       double m13,
                       double m21,
                       double m22,
                       double m23,
                       double m31,
                       double m32,
                       double m33)
        Constructs a 3 x 3 matrix with specified components.
        Parameters:
        m11 - matrix element at row 1, column 1
        m12 - matrix element at row 1, column 2
        m13 - matrix element at row 1, column 3
        m21 - matrix element at row 2, column 1
        m22 - matrix element at row 2, column 2
        m23 - matrix element at row 2, column 3
        m31 - matrix element at row 3, column 1
        m32 - matrix element at row 3, column 2
        m33 - matrix element at row 3, column 3
      • Matrix3

        public Matrix3​(Matrix3 matrix)
        Constructs a 3 x 3 matrix with the components of a specified matrix.
        Parameters:
        matrix - the matrix specifying the new components
        Throws:
        java.lang.IllegalArgumentException - If the matrix is null
    • Method Detail

      • equals

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

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

        @NonNull
        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • set

        public Matrix3 set​(double m11,
                           double m12,
                           double m13,
                           double m21,
                           double m22,
                           double m23,
                           double m31,
                           double m32,
                           double m33)
        Sets this 3 x 3 matrix to specified components.
        Parameters:
        m11 - matrix element at row 1, column 1
        m12 - matrix element at row 1, column 2
        m13 - matrix element at row 1, column 3
        m21 - matrix element at row 2, column 1
        m22 - matrix element at row 2, column 2
        m23 - matrix element at row 2, column 3
        m31 - matrix element at row 3, column 1
        m32 - matrix element at row 3, column 2
        m33 - matrix element at row 3, column 3
        Returns:
        this matrix set to the specified components
      • set

        public Matrix3 set​(Matrix3 matrix)
        Sets this 3 x 3 matrix to the components of a specified matrix.
        Parameters:
        matrix - the matrix specifying the new components
        Returns:
        this matrix with its components set to that of the specified matrix
        Throws:
        java.lang.IllegalArgumentException - If the matrix is null
      • setTranslation

        public Matrix3 setTranslation​(double x,
                                      double y)
        Sets the translation components of this matrix to specified values.
        Parameters:
        x - the X translation component
        y - the Y translation component
        Returns:
        this matrix with its translation components set to the specified values and all other components unmodified
      • setRotation

        public Matrix3 setRotation​(double angleDegrees)
        Sets the rotation components of this matrix to a specified angle. Positive angles are interpreted as counter-clockwise rotation.
        Parameters:
        angleDegrees - the angle of rotation in degrees
        Returns:
        this matrix with its rotation components set to the specified values and all other components unmodified
      • setScale

        public Matrix3 setScale​(double xScale,
                                double yScale)
        Sets the scale components of this matrix to specified values.
        Parameters:
        xScale - the X scale component
        yScale - the Y scale component
        Returns:
        this matrix with its scale components set to the specified values and all other components unmodified
      • setToIdentity

        public Matrix3 setToIdentity()
        Sets this matrix to the 3 x 3 identity matrix.
        Returns:
        this matrix, set to the identity matrix
      • setToTranslation

        public Matrix3 setToTranslation​(double x,
                                        double y)
        Sets this matrix to a translation matrix with specified translation components.
        Parameters:
        x - the X translation component
        y - the Y translation component
        Returns:
        this matrix with its translation components set to those specified and all other components set to that of an identity matrix
      • setToRotation

        public Matrix3 setToRotation​(double angleDegrees)
        Sets this matrix to a rotation matrix with a specified angle. Positive angles are interpreted as counter-clockwise rotation.
        Parameters:
        angleDegrees - the angle of rotation in degrees
        Returns:
        this matrix with its rotation components set to those specified and all other components set to that of an identity matrix
      • setToScale

        public Matrix3 setToScale​(double xScale,
                                  double yScale)
        Sets this matrix to a scale matrix with specified scale components.
        Parameters:
        xScale - the X scale component
        yScale - the Y scale component
        Returns:
        this matrix with its scale components set to those specified and all other components set to that of an identity matrix
      • setToVerticalFlip

        public Matrix3 setToVerticalFlip()
        Sets this matrix to one that flips and shifts the y-axis. The resultant matrix maps Y=0 to Y=1 and Y=1 to Y=0. All existing values are overwritten. This matrix is usually used to change the coordinate origin from an upper left coordinate origin to a lower left coordinate origin.
        This matrix is typically necessary to align the coordinate system of images (top-left origin) with that of OpenGL (bottom-left origin).
        Returns:
        this matrix set to values described above
      • setToTileTransform

        public Matrix3 setToTileTransform​(Sector src,
                                          Sector dst)
        Sets this matrix to one that transforms normalized coordinates from a source sector to a destination sector. Normalized coordinates within a sector range from 0 to 1, with (0, 0) indicating the lower left corner and (1, 1) indicating the upper right. The resultant matrix maps a normalized source coordinate (X, Y) to its corresponding normalized destination coordinate (X', Y').
        This matrix typically necessary to transform texture coordinates from one geographic region to another. For example, the texture coordinates for a terrain tile spanning one region must be transformed to coordinates appropriate for an image tile spanning a potentially different region.
        Parameters:
        src - the source sector
        dst - the destination sector
        Returns:
        this matrix set to values described above
      • setToMultiply

        public Matrix3 setToMultiply​(Matrix3 a,
                                     Matrix3 b)
        Sets this matrix to the matrix product of two specified matrices.
        Parameters:
        a - the first matrix multiplicand
        b - The second matrix multiplicand
        Returns:
        this matrix set to the product of a x b
        Throws:
        java.lang.IllegalArgumentException - If either matrix is null
      • multiplyByTranslation

        public Matrix3 multiplyByTranslation​(double x,
                                             double y)
        Multiplies this matrix by a translation matrix with specified translation values.
        Parameters:
        x - the X translation component
        y - the Y translation component
        Returns:
        this matrix multiplied by the translation matrix implied by the specified values
      • multiplyByRotation

        public Matrix3 multiplyByRotation​(double angleDegrees)
        Multiplies this matrix by a rotation matrix about a specified axis and angle. Positive angles are interpreted as counter-clockwise rotation.
        Parameters:
        angleDegrees - the angle of rotation in degrees
        Returns:
        this matrix multiplied by the rotation matrix implied by the specified values
      • multiplyByScale

        public Matrix3 multiplyByScale​(double xScale,
                                       double yScale)
        Multiplies this matrix by a scale matrix with specified values.
        Parameters:
        xScale - the X scale component
        yScale - the Y scale component
        Returns:
        this matrix multiplied by the scale matrix implied by the specified values
      • multiplyByVerticalFlip

        public Matrix3 multiplyByVerticalFlip()
        Multiplies this matrix by a matrix that flips and shifts the y-axis. The vertical flip matrix maps Y=0 to Y=1 and Y=1 to Y=0. This matrix is usually used to change the coordinate origin from an upper left coordinate origin to a lower left coordinate origin.
        This is typically necessary to align the coordinate system of images (top-left origin) with that of OpenGL (bottom-left origin).
        Returns:
        this matrix multiplied by a vertical flip matrix implied by values described above
      • multiplyByTileTransform

        public Matrix3 multiplyByTileTransform​(Sector src,
                                               Sector dst)
        Multiplies this matrix by a matrix that transforms normalized coordinates from a source sector to a destination sector. Normalized coordinates within a sector range from 0 to 1, with (0, 0) indicating the lower left corner and (1, 1) indicating the upper right. The resultant matrix maps a normalized source coordinate (X, Y) to its corresponding normalized destination coordinate (X', Y').
        This matrix typically necessary to transform texture coordinates from one geographic region to another. For example, the texture coordinates for a terrain tile spanning one region must be transformed to coordinates appropriate for an image tile spanning a potentially different region.
        Parameters:
        src - the source sector
        dst - the destination sector
        Returns:
        this matrix multiplied by the transform matrix implied by values described above
      • multiplyByMatrix

        public Matrix3 multiplyByMatrix​(Matrix3 matrix)
        Multiplies this matrix by a specified matrix.
        Parameters:
        matrix - the matrix to multiply with this matrix
        Returns:
        this matrix after multiplying it by the specified matrix
        Throws:
        java.lang.IllegalArgumentException - If the matrix is null
      • multiplyByMatrix

        public Matrix3 multiplyByMatrix​(double m11,
                                        double m12,
                                        double m13,
                                        double m21,
                                        double m22,
                                        double m23,
                                        double m31,
                                        double m32,
                                        double m33)
        Multiplies this matrix by a matrix specified by individual components.
        Parameters:
        m11 - matrix element at row 1, column 1
        m12 - matrix element at row 1, column 2
        m13 - matrix element at row 1, column 3
        m21 - matrix element at row 2, column 1
        m22 - matrix element at row 2, column 2
        m23 - matrix element at row 2, column 3
        m31 - matrix element at row 3, column 1
        m32 - matrix element at row 3, column 2
        m33 - matrix element at row 3, column 3
        Returns:
        this matrix with its components multiplied by the specified values
      • transpose

        public Matrix3 transpose()
        Transposes this matrix in place.
        Returns:
        this matrix, transposed.
      • transposeMatrix

        public Matrix3 transposeMatrix​(Matrix3 matrix)
        Transposes the specified matrix and stores the result in this matrix.
        Parameters:
        matrix - the matrix whose transpose is computed
        Returns:
        this matrix set to the transpose of the specified matrix
        Throws:
        java.lang.IllegalArgumentException - If the matrix in null
      • transposeToArray

        public float[] transposeToArray​(float[] result,
                                        int offset)
        Transposes this matrix, storing the result in the specified single precision array. The result is compatible with GLSL uniform matrices, and can be passed to the function glUniformMatrix3fv.
        Parameters:
        result - a pre-allocated array of length 9 in which to return the transposed components
        Returns:
        the result argument set to the transponsed components
      • invert

        public Matrix3 invert()
        Inverts this matrix in place.
        This throws an exception if this matrix is singular.
        Returns:
        this matrix, inverted
        Throws:
        java.lang.IllegalArgumentException - If this matrix cannot be inverted
      • invertMatrix

        public Matrix3 invertMatrix​(Matrix3 matrix)
        Inverts the specified matrix and stores the result in this matrix.
        This throws an exception if the matrix is singular.
        The result of this method is undefined if this matrix is passed in as the matrix to invert.
        Parameters:
        matrix - the matrix whose inverse is computed
        Returns:
        this matrix set to the inverse of the specified matrix
        Throws:
        java.lang.IllegalArgumentException - If the matrix is null or cannot be inverted