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, Θ.

Here is the 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 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.

Did you like this challenge?

Click on a star to rate it!

Average rating 4 / 5. Vote count: 12

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!