Matrices are another important structure in Unity. The position, rotation, and scale in a Transform component is stored in a matrix. A matrix is a 2D array and can be thought of as table with rows and columns.
Defining matrices
In Unity, a Matrix4x4 is used where the basis vectors are defined column wise in the 3x3 section of the table. Note that in other systems, they may be defined as rows. The x axis would span as [1, 0, 0] in the first column, the y as [0, 1, 0] in the second column and z as [0, 0, 1] in the last column. This part of the table gives us the orientation or in other words, the rotation. The last column is used for the position. Scale is represented by the values in the orientation so a [2, 0, 0] would be mean the x coordinate is scaled by two.
The final row is the w component and is needed for the math to work. The last column value of a w component also plays a role in how a vector is transformed. A zero would mean that position is not taken into account (relative vector; same vector but just in a different space) while a value of one would (treated as a point).
So what makes matrices important? It is useful in transforming a vector when multiplied by the matrix. For example, Unity simplifies the process of space transformations using matrices. Matrices can also be multiplied by another matrix which combines the transformations.
// Local to world
transform.TransformPoint(localPoint); // w is 1
transform.TransformVector(localVector); // w is 0
// World to local
transform.InverseTransformPoint(worldPoint);
transform.InverseTransformVector(worldVector);
// TransformDirection(vector) would give a normalized vector
// There are also built in matrices such as localToWorldMatrix
// if manual matrix manipulation is desired
An efficient way to do 90 degree rotations without the use of matrices or quaternions would be to swap the x and y coordinates and negate one to get the rotation. Which one to negate depends on which direction the rotation should occur.