Class PMatrix2D

java.lang.Object
processing.core.PMatrix2D
All Implemented Interfaces:
PMatrix

public class PMatrix2D extends Object implements PMatrix
3x2 affine matrix implementation. Matrices are used to describe a transformation; see PMatrix for a general description. This matrix looks like the following when multiplying a vector (x, y) in mult().
 [m00 m01 m02][x]   [m00*x + m01*y + m02*1]   [x']
 [m10 m11 m12][y] = [m10*x + m11*y + m12*1] = [y']
 [ 0   0   1 ][1]   [ 0*x  +  0*y  +  1*1 ]   [ 1]
(x', y') is returned. The values in the matrix determine the transformation. They are modified by the various transformation functions.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    float
     
    float
     
    float
     
    float
     
    float
     
    float
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a new matrix, set to the identity matrix.
    PMatrix2D(float m00, float m01, float m02, float m10, float m11, float m12)
     
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    apply(float n00, float n01, float n02, float n10, float n11, float n12)
    Multiply this matrix by another.
    void
    apply(float n00, float n01, float n02, float n03, float n10, float n11, float n12, float n13, float n20, float n21, float n22, float n23, float n30, float n31, float n32, float n33)
    Unavailable in 2D.
    void
    apply(PMatrix source)
    Multiply this matrix by another.
    void
    apply(PMatrix2D source)
    Multiply this matrix by another.
    void
    apply(PMatrix3D source)
    Unavailable in 2D.
    float
     
    get()
    Returns a copy of this PMatrix.
    float[]
    get(float[] target)
    Copies the matrix contents into a 6 entry float array.
    boolean
    Invert this matrix.
    float[]
    mult(float[] vec, float[] out)
    Multiply a two element vector against this matrix.
    mult(PVector source, PVector target)
    Multiply source by this matrix, and return the result.
    float
    multX(float x, float y)
    Returns the x-coordinate of the result of multiplying the point (x, y) by this matrix.
    float
    multY(float x, float y)
    Returns the y-coordinate of the result of multiplying the point (x, y) by this matrix.
    void
    preApply(float n00, float n01, float n02, float n10, float n11, float n12)
    Apply another matrix to the left of this one.
    void
    preApply(float n00, float n01, float n02, float n03, float n10, float n11, float n12, float n13, float n20, float n21, float n22, float n23, float n30, float n31, float n32, float n33)
    Unavailable in 2D.
    void
    preApply(PMatrix source)
    Apply another matrix to the left of this one.
    void
    Apply another matrix to the left of this one.
    void
    Unavailable in 2D.
    void
     
    void
    Make this an identity matrix.
    void
    rotate(float angle)
     
    void
    rotate(float angle, float v0, float v1, float v2)
    Unavailable in 2D.
    void
    rotateX(float angle)
    Unavailable in 2D.
    void
    rotateY(float angle)
    Unavailable in 2D.
    void
    rotateZ(float angle)
     
    void
    scale(float s)
     
    void
    scale(float sx, float sy)
     
    void
    scale(float x, float y, float z)
    Unavailable in 2D.
    void
    set(float[] source)
    Set the contents of this matrix to the contents of source.
    void
    set(float m00, float m01, float m02, float m10, float m11, float m12)
    Sets the matrix content.
    void
    set(float m00, float m01, float m02, float m03, float m10, float m11, float m12, float m13, float m20, float m21, float m22, float m23, float m30, float m31, float m32, float m33)
    Unavailable in 2D.
    void
    set(PMatrix matrix)
    If matrix is a PMatrix2D, sets this matrix to be a copy of it.
    void
    Unavailable in 2D.
    void
    shearX(float angle)
     
    void
    shearY(float angle)
     
    void
    translate(float tx, float ty)
     
    void
    translate(float x, float y, float z)
    Unavailable in 2D.
    void
    Unavailable in 2D.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • m00

      public float m00
    • m01

      public float m01
    • m02

      public float m02
    • m10

      public float m10
    • m11

      public float m11
    • m12

      public float m12
  • Constructor Details

    • PMatrix2D

      public PMatrix2D()
      Create a new matrix, set to the identity matrix.
    • PMatrix2D

      public PMatrix2D(float m00, float m01, float m02, float m10, float m11, float m12)
    • PMatrix2D

      public PMatrix2D(PMatrix matrix)
  • Method Details

    • reset

      public void reset()
      Description copied from interface: PMatrix
      Make this an identity matrix. Multiplying by it will have no effect.
      Specified by:
      reset in interface PMatrix
    • get

      public PMatrix2D get()
      Returns a copy of this PMatrix.
      Specified by:
      get in interface PMatrix
    • get

      public float[] get(float[] target)
      Copies the matrix contents into a 6 entry float array. If target is null (or not the correct size), a new array will be created. Returned in the order {m00, m01, m02, m10, m11, m12}.
      Specified by:
      get in interface PMatrix
    • set

      public void set(PMatrix matrix)
      If matrix is a PMatrix2D, sets this matrix to be a copy of it.
      Specified by:
      set in interface PMatrix
      Throws:
      IllegalArgumentException - If matrix is not 2D.
    • set

      public void set(PMatrix3D src)
      Unavailable in 2D. Does nothing.
    • set

      public void set(float[] source)
      Description copied from interface: PMatrix
      Set the contents of this matrix to the contents of source. Fills the matrix left-to-right, starting in the top row.
      Specified by:
      set in interface PMatrix
    • set

      public void set(float m00, float m01, float m02, float m10, float m11, float m12)
      Sets the matrix content.
      Specified by:
      set in interface PMatrix
    • set

      public void set(float m00, float m01, float m02, float m03, float m10, float m11, float m12, float m13, float m20, float m21, float m22, float m23, float m30, float m31, float m32, float m33)
      Unavailable in 2D. Does nothing.
      Specified by:
      set in interface PMatrix
    • translate

      public void translate(float tx, float ty)
      Specified by:
      translate in interface PMatrix
    • translate

      public void translate(float x, float y, float z)
      Unavailable in 2D.
      Specified by:
      translate in interface PMatrix
      Throws:
      IllegalArgumentException
    • rotate

      public void rotate(float angle)
      Specified by:
      rotate in interface PMatrix
    • rotateX

      public void rotateX(float angle)
      Unavailable in 2D.
      Specified by:
      rotateX in interface PMatrix
      Throws:
      IllegalArgumentException
    • rotateY

      public void rotateY(float angle)
      Unavailable in 2D.
      Specified by:
      rotateY in interface PMatrix
      Throws:
      IllegalArgumentException
    • rotateZ

      public void rotateZ(float angle)
      Specified by:
      rotateZ in interface PMatrix
    • rotate

      public void rotate(float angle, float v0, float v1, float v2)
      Unavailable in 2D.
      Specified by:
      rotate in interface PMatrix
      Throws:
      IllegalArgumentException
    • scale

      public void scale(float s)
      Specified by:
      scale in interface PMatrix
    • scale

      public void scale(float sx, float sy)
      Specified by:
      scale in interface PMatrix
    • scale

      public void scale(float x, float y, float z)
      Unavailable in 2D.
      Specified by:
      scale in interface PMatrix
      Throws:
      IllegalArgumentException
    • shearX

      public void shearX(float angle)
      Specified by:
      shearX in interface PMatrix
    • shearY

      public void shearY(float angle)
      Specified by:
      shearY in interface PMatrix
    • apply

      public void apply(PMatrix source)
      Description copied from interface: PMatrix
      Multiply this matrix by another.
      Specified by:
      apply in interface PMatrix
    • apply

      public void apply(PMatrix2D source)
      Description copied from interface: PMatrix
      Multiply this matrix by another.
      Specified by:
      apply in interface PMatrix
    • apply

      public void apply(PMatrix3D source)
      Unavailable in 2D.
      Specified by:
      apply in interface PMatrix
      Throws:
      IllegalArgumentException
    • apply

      public void apply(float n00, float n01, float n02, float n10, float n11, float n12)
      Description copied from interface: PMatrix
      Multiply this matrix by another.
      Specified by:
      apply in interface PMatrix
    • apply

      public void apply(float n00, float n01, float n02, float n03, float n10, float n11, float n12, float n13, float n20, float n21, float n22, float n23, float n30, float n31, float n32, float n33)
      Unavailable in 2D.
      Specified by:
      apply in interface PMatrix
      Throws:
      IllegalArgumentException
    • preApply

      public void preApply(PMatrix source)
      Apply another matrix to the left of this one.
      Specified by:
      preApply in interface PMatrix
    • preApply

      public void preApply(PMatrix2D left)
      Description copied from interface: PMatrix
      Apply another matrix to the left of this one.
      Specified by:
      preApply in interface PMatrix
    • preApply

      public void preApply(PMatrix3D left)
      Unavailable in 2D.
      Specified by:
      preApply in interface PMatrix
      Throws:
      IllegalArgumentException
    • preApply

      public void preApply(float n00, float n01, float n02, float n10, float n11, float n12)
      Description copied from interface: PMatrix
      Apply another matrix to the left of this one.
      Specified by:
      preApply in interface PMatrix
    • preApply

      public void preApply(float n00, float n01, float n02, float n03, float n10, float n11, float n12, float n13, float n20, float n21, float n22, float n23, float n30, float n31, float n32, float n33)
      Unavailable in 2D.
      Specified by:
      preApply in interface PMatrix
      Throws:
      IllegalArgumentException
    • mult

      public PVector mult(PVector source, PVector target)
      Multiply source by this matrix, and return the result. The result will be stored in target if target is non-null, and target will then be the matrix returned. This improves performance if you reuse target, so it's recommended if you call this many times in draw(). Ignores any z component.
      Specified by:
      mult in interface PMatrix
    • mult

      public float[] mult(float[] vec, float[] out)
      Multiply a two element vector against this matrix. If out is null or not length four, a new float array will be returned. The values for vec and out can be the same (though that's less efficient).
      Specified by:
      mult in interface PMatrix
    • multX

      public float multX(float x, float y)
      Returns the x-coordinate of the result of multiplying the point (x, y) by this matrix.
    • multY

      public float multY(float x, float y)
      Returns the y-coordinate of the result of multiplying the point (x, y) by this matrix.
    • transpose

      public void transpose()
      Unavailable in 2D. Does nothing.
      Specified by:
      transpose in interface PMatrix
    • invert

      public boolean invert()
      Description copied from interface: PMatrix
      Invert this matrix. Will not necessarily succeed, because some matrices map more than one point to the same image point, and so are irreversible.
      Specified by:
      invert in interface PMatrix
      Returns:
      true if successful
    • determinant

      public float determinant()
      Specified by:
      determinant in interface PMatrix
      Returns:
      the determinant of the matrix
    • print

      public void print()