Game Development Reference
In-Depth Information
We had previously determined that
x = r cos α
and y = sin
β
we substitute them to get
At this point, we can rotate any arbitrary point
p
by an angle
β
, and the result will be the
point
p'
.
Now we could implement this equation in code as a function that receives a point and an
angle and use it to perform the rotations we need. While this may work well enough for
very simple cases, it often results in sub-optimal or difficult to maintain code. There is a
more versatile tool we can use that will allow us to build a mechanism by which we can
perform rotations, as well as chain together multiple rotations; it is the standard method
used in graphics programming, for this we turn to linear algebra.
Inlinearalgebra,wecanrepresenttherotation equationwederivedpreviouslyusingamat-
rix.
This matrix will rotate any point represented by a column vector
v
containing the coordin-
ates of the point.
We obtain the rotated vector
v'
by multiplying the vector v by the rotation matrix.