Skip to main content

Matrix2D

                            
                              
                                class 
                                Matrix2D
                                implements 
                                
                                  
                                    
                                      Type
                                    
                                  
                                
                              
                              

A specialized 2x3 Matrix representing a 2D transformation.

A Matrix2D contains six elements defined as[a, b,c, d,tx, ty]

This is a shortcut for a 3x3 matrix of the form[a, b, 0,c, d, 0tx, ty, 1]

Note that because a Matrix2D ignores the z-values of each component vectors,it does not satisfy all properties of a "real" 3x3 matrix.

  • A Matrix2D has no transpose
  • A(B + C) = AB + AC does not hold for a Matrix2D
  • (rA)^-1 = r^-1 A^-1, r != 0 does not hold for a Matrix2D
  • r(AB) = (rA)B = A(rB) does not hold for a Matrix2D

Constructors

constructor

                            
                              
                                public 
                                new
                                Matrix2D
                                (): 
                                Matrix2D
                              
                              
                            
                              
                                public 
                                new
                                Matrix2D
                                
                                  
                                    
                                      matrix
                                      : 
                                      PossibleMatrix2D
                                    
                                  
                                
                                : 
                                Matrix2D
                              
                              
                            
                              
                                public 
                                new
                                Matrix2D
                                
                                  
                                    
                                      x
                                      : 
                                      PossibleVector2
                                      
                                        
                                          
                                            number
                                          
                                        
                                      
                                    
                                    
                                      y
                                      : 
                                      PossibleVector2
                                      
                                        
                                          
                                            number
                                          
                                        
                                      
                                    
                                    
                                      z
                                      : 
                                      PossibleVector2
                                      
                                        
                                          
                                            number
                                          
                                        
                                      
                                    
                                  
                                
                                : 
                                Matrix2D
                              
                              
                            
                              
                                public 
                                new
                                Matrix2D
                                
                                  
                                    
                                      a
                                      : 
                                      number
                                    
                                    
                                      b
                                      : 
                                      number
                                    
                                    
                                      c
                                      : 
                                      number
                                    
                                    
                                      d
                                      : 
                                      number
                                    
                                    
                                      tx
                                      : 
                                      number
                                    
                                    
                                      ty
                                      : 
                                      number
                                    
                                  
                                
                                : 
                                Matrix2D
                              
                              

Properties

values

                            
                              
                                readonly 
                                public 
                                values
                                : 
                                Float32Array
                                 = 
                                ...
                              
                              

identity

                            
                              
                                static 
                                readonly 
                                public 
                                identity
                                : 
                                Matrix2D
                                 = 
                                ...
                              
                              

symbol

                            
                              
                                static 
                                readonly 
                                public 
                                symbol
                                : 
                                typeof 
                                symbol
                                 = 
                                ...
                              
                              

zero

                            
                              
                                static 
                                readonly 
                                public 
                                zero
                                : 
                                Matrix2D
                                 = 
                                ...
                              
                              

Accessors

determinant

                            
                              
                                public 
                                get 
                                determinant
                                (): 
                                number
                              
                              

Get the determinant of the matrix.


domMatrix

                            
                              
                                public 
                                get 
                                domMatrix
                                (): 
                                DOMMatrix
                              
                              

inverse

                            
                              
                                public 
                                get 
                                inverse
                                (): 
                                
                                  
                                    
                                      null
                                    
                                    
                                      Matrix2D
                                    
                                  
                                
                              
                              

Get the inverse of the matrix.

If the matrix is not invertible, i.e. its determinant is 0 , this willreturn null , instead.

Examples


rotation

                            
                              
                                public 
                                set 
                                rotation
                                
                                  
                                    
                                      angle
                                      : 
                                      number
                                    
                                  
                                
                                : 
                                void
                              
                              
                            
                              
                                public 
                                get 
                                rotation
                                (): 
                                number
                              
                              

Parameters


scaleX

                            
                              
                                public 
                                set 
                                scaleX
                                
                                  
                                    
                                      value
                                      : 
                                      number
                                    
                                  
                                
                                : 
                                void
                              
                              
                            
                              
                                public 
                                get 
                                scaleX
                                (): 
                                number
                              
                              

Parameters


scaleY

                            
                              
                                public 
                                set 
                                scaleY
                                
                                  
                                    
                                      value
                                      : 
                                      number
                                    
                                  
                                
                                : 
                                void
                              
                              
                            
                              
                                public 
                                get 
                                scaleY
                                (): 
                                number
                              
                              

Parameters


scaling

                            
                              
                                public 
                                set 
                                scaling
                                
                                  
                                    
                                      value
                                      : 
                                      PossibleVector2
                                      
                                        
                                          
                                            number
                                          
                                        
                                      
                                    
                                  
                                
                                : 
                                void
                              
                              
                            
                              
                                public 
                                get 
                                scaling
                                (): 
                                Vector2
                              
                              

Parameters


skewX

                            
                              
                                public 
                                set 
                                skewX
                                
                                  
                                    
                                      value
                                      : 
                                      number
                                    
                                  
                                
                                : 
                                void
                              
                              
                            
                              
                                public 
                                get 
                                skewX
                                (): 
                                number
                              
                              

Parameters


skewY

                            
                              
                                public 
                                set 
                                skewY
                                
                                  
                                    
                                      value
                                      : 
                                      number
                                    
                                  
                                
                                : 
                                void
                              
                              
                            
                              
                                public 
                                get 
                                skewY
                                (): 
                                number
                              
                              

Parameters


translateX

                            
                              
                                public 
                                set 
                                translateX
                                
                                  
                                    
                                      value
                                      : 
                                      number
                                    
                                  
                                
                                : 
                                void
                              
                              
                            
                              
                                public 
                                get 
                                translateX
                                (): 
                                number
                              
                              

Parameters


translateY

                            
                              
                                public 
                                set 
                                translateY
                                
                                  
                                    
                                      value
                                      : 
                                      number
                                    
                                  
                                
                                : 
                                void
                              
                              
                            
                              
                                public 
                                get 
                                translateY
                                (): 
                                number
                              
                              

Parameters


translation

                            
                              
                                public 
                                set 
                                translation
                                
                                  
                                    
                                      translation
                                      : 
                                      PossibleVector2
                                      
                                        
                                          
                                            number
                                          
                                        
                                      
                                    
                                  
                                
                                : 
                                void
                              
                              
                            
                              
                                public 
                                get 
                                translation
                                (): 
                                Vector2
                              
                              

Parameters


x

                            
                              
                                public 
                                get 
                                x
                                (): 
                                Vector2
                              
                              

y

                            
                              
                                public 
                                get 
                                y
                                (): 
                                Vector2
                              
                              

Methods

add

                            
                              
                                public 
                                add
                                
                                  
                                    
                                      other
                                      : 
                                      Matrix2D
                                    
                                  
                                
                                : 
                                Matrix2D
                              
                              

Add the provided matrix to this matrix.

This method returns a new matrix representing the result of thecomputation. It will not modify the source matrix.

Examples

Parameters

  • other : Matrix2D

    The matrix to add


column

                            
                              
                                public 
                                column
                                
                                  
                                    
                                      index
                                      : 
                                      number
                                    
                                  
                                
                                : 
                                Vector2
                              
                              

Get the nth component vector of the matrix. Only defined for 0, 1, and 2.

Examples

Parameters

  • index : number

    The index of the component vector to retrieve.


equals

                            
                              
                                public 
                                equals
                                
                                  
                                    
                                      other
                                      : 
                                      Matrix2D
                                    
                                    
                                      threshold
                                      : 
                                      number
                                       = 
                                      EPSILON
                                    
                                  
                                
                                : 
                                boolean
                              
                              

Parameters


exactlyEquals

                            
                              
                                public 
                                exactlyEquals
                                
                                  
                                    
                                      other
                                      : 
                                      Matrix2D
                                    
                                  
                                
                                : 
                                boolean
                              
                              

Parameters


mul

                            
                              
                                public 
                                mul
                                
                                  
                                    
                                      other
                                      : 
                                      Matrix2D
                                    
                                  
                                
                                : 
                                Matrix2D
                              
                              

Returns the matrix product of this matrix with the provided matrix.

This method returns a new matrix representing the result of thecomputation. It will not modify the source matrix.

Examples

Parameters

  • other : Matrix2D

    The matrix to multiply with


mulScalar

                            
                              
                                public 
                                mulScalar
                                
                                  
                                    
                                      s
                                      : 
                                      number
                                    
                                  
                                
                                : 
                                Matrix2D
                              
                              

Multiply each value of the matrix by a scalar.

Examples

Parameters

  • s : number

    The value by which to scale each term


rotate

                            
                              
                                public 
                                rotate
                                
                                  
                                    
                                      angle
                                      : 
                                      number
                                    
                                    
                                      degrees
                                      : 
                                      boolean
                                       = 
                                      true
                                    
                                  
                                
                                : 
                                Matrix2D
                              
                              

Rotate the matrix by the provided angle. By default, the angle isprovided in degrees.

This method returns a new matrix representing the result of thecomputation. It will not modify the source matrix.

Examples

Parameters

  • angle : number

    The angle by which to rotate the matrix.

  • degrees : boolean = true

    Whether the angle is provided in degrees.


row

                            
                              
                                public 
                                row
                                
                                  
                                    
                                      index
                                      : 
                                      number
                                    
                                  
                                
                                : 
                                
                                  
                                    
                                      number
                                    
                                    
                                      number
                                    
                                    
                                      number
                                    
                                  
                                
                              
                              

Returns the nth row of the matrix. Only defined for 0 and 1.

Examples

Parameters

  • index : number

    The index of the row to retrieve.


scale

                            
                              
                                public 
                                scale
                                
                                  
                                    
                                      vec
                                      : 
                                      PossibleVector2
                                      
                                        
                                          
                                            number
                                          
                                        
                                      
                                    
                                  
                                
                                : 
                                Matrix2D
                              
                              

Scale the x and y component vectors of the matrix.

If vec is provided as a vector, the x and y component vectors of thematrix will be scaled by the x and y parts of the vector, respectively.

If vec is provided as a scalar, the x and y component vectors will bescaled uniformly by this factor.

This method returns a new matrix representing the result of thecomputation. It will not modify the source matrix.

Examples

Parameters


sub

                            
                              
                                public 
                                sub
                                
                                  
                                    
                                      other
                                      : 
                                      Matrix2D
                                    
                                  
                                
                                : 
                                Matrix2D
                              
                              

Subtract the provided matrix from this matrix.

This method returns a new matrix representing the result of thecomputation. It will not modify the source matrix.

Examples

Parameters

  • other : Matrix2D

    The matrix to subract


toSymbol

                            
                              
                                public 
                                toSymbol
                                (): 
                                symbol
                              
                              

translate

                            
                              
                                public 
                                translate
                                
                                  
                                    
                                      vec
                                      : 
                                      PossibleVector2
                                      
                                        
                                          
                                            number
                                          
                                        
                                      
                                    
                                  
                                
                                : 
                                Matrix2D
                              
                              

Translate the matrix by the dimensions of the provided vector.

If vec is provided as a scalar, matrix will be translated uniformlyby this factor.

This method returns a new matrix representing the result of thecomputation. It will not modify the source matrix.

Examples

Parameters


fromRotation

                            
                              
                                static 
                                public 
                                fromRotation
                                
                                  
                                    
                                      angle
                                      : 
                                      number
                                    
                                  
                                
                                : 
                                Matrix2D
                              
                              

Parameters


fromScaling

                            
                              
                                static 
                                public 
                                fromScaling
                                
                                  
                                    
                                      scale
                                      : 
                                      PossibleVector2
                                      
                                        
                                          
                                            number
                                          
                                        
                                      
                                    
                                  
                                
                                : 
                                Matrix2D
                              
                              

Parameters


fromTranslation

                            
                              
                                static 
                                public 
                                fromTranslation
                                
                                  
                                    
                                      translation
                                      : 
                                      PossibleVector2
                                      
                                        
                                          
                                            number
                                          
                                        
                                      
                                    
                                  
                                
                                : 
                                Matrix2D
                              
                              

Parameters