Class representing an affine transformation 3x3 matrix:

     [ a  c  tx
A =    b  d  ty
       0  0  1  ]

Constructors

  • Construct new instance of affine transformation matrix
    If parameters omitted, construct identity matrix a = 1, d = 1

    Parameters

    • a: number = 1

      position(0,0) sx*cos(alpha)

    • b: number = 0

      position (0,1) sx*sin(alpha)

    • c: number = 0

      position (1,0) -sy*sin(alpha)

    • d: number = 1

      position (1,1) sy*cos(alpha)

    • tx: number = 0

      position (2,0) translation by x

    • ty: number = 0

      position (2,1) translation by y

    Returns Matrix

Properties

a: number
b: number
c: number
d: number
tx: number
ty: number

Methods

  • Return new cloned instance of matrix

    Returns Matrix

  • Returns true if two matrix are equal parameter by parameter

    Parameters

    Returns boolean

    true if equal, false otherwise

  • Multiplication of two matrix.

    Parameters

    • otherMatrix: Matrix

      matrix to multiply by

    Returns Matrix

    result of multiplication of this matrix by other matrix

  • Rotate matrix by given angle (in radians) around center of rotation (0,0) in counterclockwise direction.

    Parameters

    • angle: number

      angle in radians

    • centerX: number = 0.0

      center of rotation

    • centerY: number = 0.0

      center of rotation

    Returns Matrix

    new matrix as a result of multiplication of the current matrix by the matrix that defines rotation by given angle (in radians) around center of rotation (centerX,centerY) in counterclockwise direction

  • Scale matrix by a factor sx along the x-axis and sy along the y-axis.

    Parameters

    • sx: number
    • sy: number

    Returns Matrix

    new matrix as a result of multiplication of the current matrix by the matrix (sx,0,0,sy,0,0) that defines scaling

  • Transform vector [x,y] using transformation matrix.
    Vector [x,y] is an abstract array[2] of numbers and not a FlattenJS object
    The result is also an abstract vector [x',y'] = A * [x,y]: [x' [ ax + by + tx y' = cx + dy + ty 1] 1 ]

    Parameters

    • vector: [number, number]

      array[2] of numbers

    Returns [number, number]

    transformation result - array[2] of numbers

  • Translate matrix by vector or by pair of numbers.

    Parameters

    • Rest...args: [number, number] | [{
          x: number;
          y: number;
      }]

      Translation vector or translation by x and y

    Returns Matrix

    new matrix as a result of multiplication of the current matrix by the matrix(1,0,0,1,tx,ty)