Math.Matrix2D Class
Matrix2D class, represent a matrix object for perform geometric calculus. The default matrix is the identity matrix.
Constructor
Math.Matrix2D
()
Example:
new Matrix2D()
generate this matrix:
[1 0 0]
[0 1 0]
[0 0 1]
Item Index
Methods
- copyMatrix
- getData
- identity static
- identity
- inverse
- isIdentity
- multiply
- multiplyVector
- rotate
- rotation static
- scale
- scale static
- setTransform
- skew
- skew static
- toString
- transform
- transformContext
- translate
- translation static
Properties
Methods
copyMatrix
()
Matrix2D
create a copy of the matrix.
Returns:
getData
()
Array
Get a copy of the current state of the matrix by a 2d array of floats.
Note: if you want to modify the matrix, you can access directly to matrix.data
Returns:
identity
()
Matrix2D
static
This method returns an identity matrix.
Returns:
identity
()
chainable
Set the current matrix to identity.
inverse
()
Matrix2D
Compute the inverse matrix of this.
Returns:
null
isIdentity
()
Boolean
Check if the current matrix match the identity.
Returns:
true
if the current matrix is set to the identity, otherwise it returns false
.
multiply
-
matrix
Compute the product of two matrix
Parameters:
-
matrix
Matrix2Dthe matrix to multiplies
multiplyVector
-
vector
Multiplies the current matrix by a vector 2d.
Parameters:
-
vector
Vector2D
Returns:
rotate
-
angle
Apply a rotation to this matrix.
Parameters:
-
angle
Numberin degrees
rotation
-
angle
This method returns a rotation matrix Note that the angle is expressed in degree
Parameters:
-
angle
Objecta scalar expressed in degree who represent the angle of rotation of the matrix to generate.
Returns:
scale
-
x
-
y
multiplies the current matrix by scale matrix
Parameters:
-
x
Numbermultiplier of abscissa
-
y
Numbermultiplier of ordinate
scale
-
x
-
y
This method return a scale matrix
Parameters:
-
x
Objectthe abscissa scale factor to integrate in the matrix
-
y
Objectthe ordinate scale factor to integrate in the matrix
Returns:
setTransform
-
a
-
b
-
c
-
d
-
e
-
f
Set the current matrix to the specified scalars (a, b, c, d, e, f). Note that the parameters are given in column major order.
Parameters:
-
a
Objectrepresent the top-left scalar in the matrix
-
b
Objectrepresent the middle-left scalar in the matrix
-
c
Objectrepresent the top-center scalar in the matrix
-
d
Objectrepresent the middle-middle scalar in the matrix
-
e
Objectrepresent the top-left scalar in the matrix
-
f
Objectrepresent the middle-right scalar in the matrix
skew
-
a
-
b
Transform the current matrix to apply a skew.
Parameters:
-
a
Objectthe x skew factor
-
b
Objectthe y skew factor
Returns:
skew
-
a
-
b
This method return a skew matrix
Parameters:
-
a
Objectthe factor of skew on the y axis
-
b
Objectthe factor of skew on the x axis
Returns:
toString
()
String
give a data representation of Matrix
Returns:
transform
-
a
-
b
-
c
-
d
-
e
-
f
Transform the current matrix by the scalars a,b,c,d,e,f. If C if our current matrix and B the matrix made by a,b,c,d,e,f scalars. Then, the transform will be :
C Matrix B matrix
[Ca, Cc, Ce] [a, c, e]
[Cb, Cd, Cf] X [b, d, f]
[0, 0, 1] [0, 0, 1]
Parameters:
-
a
Object -
b
Object -
c
Object -
d
Object -
e
Object -
f
Object
transformContext
-
context
This method transform the context given in parameter by the current matrix.
Parameters:
-
context
CanvasRenderingContext2Dit is the context to transform by the current matrix.
translate
-
x
-
y
Apply a translation to this matrix.
Parameters:
-
x
Numbertranslation in abscissa
-
y
Numbertranslation in ordinate
translation
-
x
-
y
This method return a translation matrix
Parameters:
-
x
Objectthe x translation to integrate in the matrix
-
y
Objectthe y translation to integrate in the matrix
Returns:
Properties
data
Array
Internal data that represent matrix.
Note that datas are given in column major order.
Example:
[[1, 0, 0],
[0, 1, 0],
[0, 0, 1]]