Class Matrix3d

java.lang.Object
gaiasky.util.math.Matrix3d
All Implemented Interfaces:
Serializable

public class Matrix3d extends Object implements Serializable
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    double[]
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    Matrix3d(double[] values)
    Constructs a matrix from the given double array.
     
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    det()
     
    double
     
    double
     
     
     
    double[]
    Get the values in this matrix.
    idt()
    Sets this matrix to the identity matrix
    inv()
    Inverts this matrix given that the determinant is != 0.
    Postmultiplies this matrix with the provided matrix and stores the result in this matrix.
    Premultiplies this matrix with the provided matrix and stores the result in this matrix.
    rotate(double degrees)
    Postmultiplies this matrix with a (counter-clockwise) rotation matrix.
    rotateRad(double radians)
    Postmultiplies this matrix with a (counter-clockwise) rotation matrix.
    scale(double scaleX, double scaleY)
    Postmultiplies this matrix with a scale matrix.
    scale(com.badlogic.gdx.math.Vector2 scale)
    Postmultiplies this matrix with a scale matrix.
    scl(double scale)
    Scale the matrix in the both the x and y components by the scalar value.
    scl(com.badlogic.gdx.math.Vector2 scale)
    Scale this matrix using the x and y components of the vector but leave the rest of the matrix alone.
    scl(com.badlogic.gdx.math.Vector3 scale)
    Scale this matrix using the x and y components of the vector but leave the rest of the matrix alone.
    set(double[] values)
    Sets the matrix to the given matrix as a double array.
    set(com.badlogic.gdx.math.Affine2 affine)
    Copies the values from the provided affine matrix to this matrix.
    set(com.badlogic.gdx.math.Matrix4 mat)
    Sets this 3x3 matrix to the top left 3x3 corner of the provided 4x4 matrix.
    Copies the values from the provided matrix to this matrix.
    setToRotation(double degrees)
    Sets this matrix to a rotation matrix that will rotate any vector in counter-clockwise direction around the z-axis.
    setToRotation(Vector3d axis, double degrees)
     
    setToRotation(Vector3d axis, double cos, double sin)
     
    setToRotationRad(double radians)
    Sets this matrix to a rotation matrix that will rotate any vector in counter-clockwise direction around the z-axis.
    setToScaling(double scaleX, double scaleY)
    Sets this matrix to a scaling matrix.
    setToScaling(com.badlogic.gdx.math.Vector2 scale)
    Sets this matrix to a scaling matrix.
    setToTranslation(double x, double y)
    Sets this matrix to a translation matrix.
    setToTranslation(com.badlogic.gdx.math.Vector2 translation)
    Sets this matrix to a translation matrix.
     
    translate(double x, double y)
    Postmultiplies this matrix by a translation matrix.
    translate(com.badlogic.gdx.math.Vector2 translation)
    Postmultiplies this matrix by a translation matrix.
    Transposes the current matrix.
    trn(double x, double y)
    Adds a translational component to the matrix in the 3rd column.
    trn(com.badlogic.gdx.math.Vector2 vector)
    Adds a translational component to the matrix in the 3rd column.
    trn(com.badlogic.gdx.math.Vector3 vector)
    Adds a translational component to the matrix in the 3rd column.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • Matrix3d

      public Matrix3d()
    • Matrix3d

      public Matrix3d(Matrix3d matrix)
    • Matrix3d

      public Matrix3d(double[] values)
      Constructs a matrix from the given double array. The array must have at least 9 elements; the first 9 will be copied.
      Parameters:
      values - The double array to copy. Remember that this matrix is in column major order. (The double array is not modified.)
  • Method Details

    • idt

      public Matrix3d idt()
      Sets this matrix to the identity matrix
      Returns:
      This matrix for the purpose of chaining operations.
    • mul

      public Matrix3d mul(Matrix3d m)
      Postmultiplies this matrix with the provided matrix and stores the result in this matrix. For example:
       A.mul(B) results in A := AB
       
      Parameters:
      m - Matrix to multiply by.
      Returns:
      This matrix for the purpose of chaining operations together.
    • mulLeft

      public Matrix3d mulLeft(Matrix3d m)
      Premultiplies this matrix with the provided matrix and stores the result in this matrix. For example:
       A.mulLeft(B) results in A := BA
       
      Parameters:
      m - The other Matrix to multiply by
      Returns:
      This matrix for the purpose of chaining operations.
    • setToRotation

      public Matrix3d setToRotation(double degrees)
      Sets this matrix to a rotation matrix that will rotate any vector in counter-clockwise direction around the z-axis.
      Parameters:
      degrees - the angle in degrees.
      Returns:
      This matrix for the purpose of chaining operations.
    • setToRotationRad

      public Matrix3d setToRotationRad(double radians)
      Sets this matrix to a rotation matrix that will rotate any vector in counter-clockwise direction around the z-axis.
      Parameters:
      radians - the angle in radians.
      Returns:
      This matrix for the purpose of chaining operations.
    • setToRotation

      public Matrix3d setToRotation(Vector3d axis, double degrees)
    • setToRotation

      public Matrix3d setToRotation(Vector3d axis, double cos, double sin)
    • setToTranslation

      public Matrix3d setToTranslation(double x, double y)
      Sets this matrix to a translation matrix.
      Parameters:
      x - the translation in x
      y - the translation in y
      Returns:
      This matrix for the purpose of chaining operations.
    • setToTranslation

      public Matrix3d setToTranslation(com.badlogic.gdx.math.Vector2 translation)
      Sets this matrix to a translation matrix.
      Parameters:
      translation - The translation vector.
      Returns:
      This matrix for the purpose of chaining operations.
    • setToScaling

      public Matrix3d setToScaling(double scaleX, double scaleY)
      Sets this matrix to a scaling matrix.
      Parameters:
      scaleX - the scale in x
      scaleY - the scale in y
      Returns:
      This matrix for the purpose of chaining operations.
    • setToScaling

      public Matrix3d setToScaling(com.badlogic.gdx.math.Vector2 scale)
      Sets this matrix to a scaling matrix.
      Parameters:
      scale - The scale vector.
      Returns:
      This matrix for the purpose of chaining operations.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • det

      public double det()
      Returns:
      The determinant of this matrix
    • inv

      public Matrix3d inv()
      Inverts this matrix given that the determinant is != 0.
      Returns:
      This matrix for the purpose of chaining operations.
      Throws:
      com.badlogic.gdx.utils.GdxRuntimeException - if the matrix is singular (not invertible)
    • set

      public Matrix3d set(Matrix3d mat)
      Copies the values from the provided matrix to this matrix.
      Parameters:
      mat - The matrix to copy.
      Returns:
      This matrix for the purposes of chaining.
    • set

      public Matrix3d set(com.badlogic.gdx.math.Affine2 affine)
      Copies the values from the provided affine matrix to this matrix. The last row is set to (0, 0, 1).
      Parameters:
      affine - The affine matrix to copy.
      Returns:
      This matrix for the purposes of chaining.
    • set

      public Matrix3d set(com.badlogic.gdx.math.Matrix4 mat)
      Sets this 3x3 matrix to the top left 3x3 corner of the provided 4x4 matrix.
      Parameters:
      mat - The matrix whose top left corner will be copied. This matrix will not be modified.
      Returns:
      This matrix for the purpose of chaining operations.
    • set

      public Matrix3d set(double[] values)
      Sets the matrix to the given matrix as a double array. The double array must have at least 9 elements; the first 9 will be copied.
      Parameters:
      values - The matrix, in double form, that is to be copied. Remember that this matrix is in column major order.
      Returns:
      This matrix for the purpose of chaining methods together.
    • trn

      public Matrix3d trn(com.badlogic.gdx.math.Vector2 vector)
      Adds a translational component to the matrix in the 3rd column. The other columns are untouched.
      Parameters:
      vector - The translation vector.
      Returns:
      This matrix for the purpose of chaining.
    • trn

      public Matrix3d trn(double x, double y)
      Adds a translational component to the matrix in the 3rd column. The other columns are untouched.
      Parameters:
      x - The x-component of the translation vector.
      y - The y-component of the translation vector.
      Returns:
      This matrix for the purpose of chaining.
    • trn

      public Matrix3d trn(com.badlogic.gdx.math.Vector3 vector)
      Adds a translational component to the matrix in the 3rd column. The other columns are untouched.
      Parameters:
      vector - The translation vector. (The z-component of the vector is ignored because this is a 3x3 matrix)
      Returns:
      This matrix for the purpose of chaining.
    • translate

      public Matrix3d translate(double x, double y)
      Postmultiplies this matrix by a translation matrix. Postmultiplication is also used by OpenGL ES' 1.x glTranslate/glRotate/glScale.
      Parameters:
      x - The x-component of the translation vector.
      y - The y-component of the translation vector.
      Returns:
      This matrix for the purpose of chaining.
    • translate

      public Matrix3d translate(com.badlogic.gdx.math.Vector2 translation)
      Postmultiplies this matrix by a translation matrix. Postmultiplication is also used by OpenGL ES' 1.x glTranslate/glRotate/glScale.
      Parameters:
      translation - The translation vector.
      Returns:
      This matrix for the purpose of chaining.
    • rotate

      public Matrix3d rotate(double degrees)
      Postmultiplies this matrix with a (counter-clockwise) rotation matrix. Postmultiplication is also used by OpenGL ES' 1.x glTranslate/glRotate/glScale.
      Parameters:
      degrees - The angle in degrees
      Returns:
      This matrix for the purpose of chaining.
    • rotateRad

      public Matrix3d rotateRad(double radians)
      Postmultiplies this matrix with a (counter-clockwise) rotation matrix. Postmultiplication is also used by OpenGL ES' 1.x glTranslate/glRotate/glScale.
      Parameters:
      radians - The angle in radians
      Returns:
      This matrix for the purpose of chaining.
    • scale

      public Matrix3d scale(double scaleX, double scaleY)
      Postmultiplies this matrix with a scale matrix. Postmultiplication is also used by OpenGL ES' 1.x glTranslate/glRotate/glScale.
      Parameters:
      scaleX - The scale in the x-axis.
      scaleY - The scale in the y-axis.
      Returns:
      This matrix for the purpose of chaining.
    • scale

      public Matrix3d scale(com.badlogic.gdx.math.Vector2 scale)
      Postmultiplies this matrix with a scale matrix. Postmultiplication is also used by OpenGL ES' 1.x glTranslate/glRotate/glScale.
      Parameters:
      scale - The vector to scale the matrix by.
      Returns:
      This matrix for the purpose of chaining.
    • getValues

      public double[] getValues()
      Get the values in this matrix.
      Returns:
      The double values that make up this matrix in column-major order.
    • getTranslation

      public Vector2d getTranslation(Vector2d position)
    • getScale

      public Vector2d getScale(Vector2d scale)
      Parameters:
      scale - The vector which will receive the (non-negative) scale components on each axis.
      Returns:
      The provided vector for chaining.
    • getRotation

      public double getRotation()
    • getRotationRad

      public double getRotationRad()
    • scl

      public Matrix3d scl(double scale)
      Scale the matrix in the both the x and y components by the scalar value.
      Parameters:
      scale - The single value that will be used to scale both the x and y components.
      Returns:
      This matrix for the purpose of chaining methods together.
    • scl

      public Matrix3d scl(com.badlogic.gdx.math.Vector2 scale)
      Scale this matrix using the x and y components of the vector but leave the rest of the matrix alone.
      Parameters:
      scale - The Vector3 to use to scale this matrix.
      Returns:
      This matrix for the purpose of chaining methods together.
    • scl

      public Matrix3d scl(com.badlogic.gdx.math.Vector3 scale)
      Scale this matrix using the x and y components of the vector but leave the rest of the matrix alone.
      Parameters:
      scale - The Vector3 to use to scale this matrix. The z component will be ignored.
      Returns:
      This matrix for the purpose of chaining methods together.
    • transpose

      public Matrix3d transpose()
      Transposes the current matrix.
      Returns:
      This matrix for the purpose of chaining methods together.