2D Rotation Matrix

In this post, we will investigate how we can use the 2D rotation matrix to calculate the coordinates of a point when applying a 2D rotation of a set angle, Θ.
2D-Rotation

Here is the 2D rotation matrix:
2D-Rotation-Matrix

Which results in the following two equations where (x,y) are the cartesian coordinates of a point before applying the rotation, (x’,y’) are the cartesian coordinates of this point after applying the rotation and Θ is the angle of rotation
2D-Rotation-Coordinates

2D Rotation Demo


We have created a demo using the processing library to represent an X-Wing spacecraft (top-down view). The spacecraft is defined as a list of shapes, where each shape is a sublist of (x,y) coordinates (the vertices of the polygonal shape).

We are then applying the 2D rotation formulas to apply an angle of rotation (calculated based on the position of the mouse cursor on the canvas) and hence calculated the new coordinates of each vertices.

Finally, using the line() function of the processing library we the draw the spacecraft by plotting and joining all these vertices together.

Share Button