5.) Writing Mat2
- Read through comments of
src/A0/math/Mat2.ts
- Search for
TODO
keyword in thesrc/A0/math/Mat2.ts
file to get started.
This assignment is designed to help you get comfortable working with Typescript.
In this assignment, we will implement some functions to make 2x2 matrix related computations much easier with a custom Mat2
class.
1. Facilitate Mat2
property accessing and setting
- Write the remaining two getters and setters for
m10
andm11
. - Write the remaining two getters and setters for
r1
andc1
. - Implement
getElement(row: number, col: number): number
.
Getter and setter functions are special member functions, serving as syntax sugers for accessing or setting a certain property of the class (like mat2.m00
)
set m00()
will be called with syntax likemat1.m00 = 1
get m00()
will be called with syntax likelet a = mat1.m00
More on getter and setter: Introduction to JavaScript getters and setters in ES6
Tips for implementing getters and setters for `m10`, `m11`, `r1`, and `c1`
Tips for implementing `getElement(row: number, col: number): number`
2. Ease the construction of a Mat2
object
- Implement
static FromRows(r0:Vec2, r1:Vec2): Mat2
- Implement
static FromColumns(c0:Vec2, c1:Vec2): Mat2
- static functions are like memeber functions of a class, accessed like
Mat2.FromRows(r2,r2)
- Here, we will implement some static functions, serving as convenient construction functions (e.g. conveniently create a
Mat2
object by callingFromRows(r0:Vec2, r1:Vec2)
)
Tips for implementing `FromRows` and `FromColumns`
3. Facilitate 2x2 matrix-vector and matrix-matrix computation
- Implement
_timesMatrix(rhs: Mat2): Mat2
- Implement
protected _timesVector(v: Vec2): Vec2
- Implement
plus(other: Mat2): Mat2
- Implement
minus(other: Mat2): Mat2
- Implement
determinant(): number
- Implement
getInverse(): Mat2 | null
Matrix Refresh Materials
4. Ease common matrix creation
- Implement
static Scale(scale: number): Mat2
- Implement
static Rotation(radians: number): Mat2
(rotate counter-clockwise)
Recall that matrices are essentially a way to transform a plane.
In this section, we will implement some common matrices that can scale or rotate a whole plane.
Recall that static functions are like memeber functions of a class, so we would call Mat2.Scale(2)
to create a matrix that will scale x and y by 2 for all points on the plane.