import { PointF2D } from "./PointF2D" ; export class Matrix2D { private matrix : number [ ] [ ] ; constructor ( ) { this . matrix = [ ] ; for ( let i = 0 ; i < 2 ; i ++ ) { this . matrix [ i ] = [ ] ; for ( let j = 0 ; j < 2 ; j ++ ) { this . matrix [ i ] [ j ] = 0 ; } } } public static getRotationMatrix ( angle ) { const rotation = new Matrix2D ( ) ; const cos = Math . cos ( angle ) ; const sin = Math . sin ( angle ) ; rotation . matrix [ 0 ] [ 0 ] = cos ; rotation . matrix [ 0 ] [ 1 ] = - sin ; rotation . matrix [ 1 ] [ 0 ] = sin ; rotation . matrix [ 1 ] [ 1 ] = cos ; return rotation ; } public scalarMultiplication ( scalar ) { for ( let i = 0 ; i < 2 ; i ++ ) { for ( let j = 0 ; j < 2 ; j ++ ) { this . matrix [ i ] [ j ] *= scalar ; } } } public getTransposeMatrix ( ) { const transpose = new Matrix2D ( ) ; for ( let i = 0 ; i < 2 ; i ++ ) { for ( let j = 0 ; j < 2 ; j ++ ) { transpose . matrix [ i ] [ j ] = this . matrix [ j ] [ i ] ; } } return transpose ; } public vectorMultiplication ( point ) { const result = new PointF2D ( ) ; result . x = point . x * this . matrix [ 0 ] [ 0 ] + point . y * this . matrix [ 0 ] [ 1 ] ; result . y = point . x * this . matrix [ 1 ] [ 0 ] + point . y * this . matrix [ 1 ] [ 1 ] ; return result ; } }