3D Challenge

3DCubeThe aim of this challenge is to draw a cube in 3D and to make it rotate on the screen.

Drawing 3D shapes on a screen (2D) requires some mathematical formulas to convert 3D (x,y,z) coordinates into 2D coordinates (x,y).

3D rotation against an axis (X, Y or Z axis) also requires some complex mathematical formulas.

This is a great application of trigonometry, especially of the SOCATOA formulas!

socatoa

cosine

sine

(Read more about trigonometric formulas.)

To apply a 3D rotation we can use the rotation matrix as follows:
3d-rotation-matrix

Our Solution:


To decide the angle and axis of rotation we use the position of the mouse pointer.
The X coordinate of the mouse pointer becomes the angle of rotation against the Y axis.
The Y coordinate of the mouse pointer becomes the angle of rotation against the X axis.
In this example we did not implement a rotation against the Z axis.

Share Button
Posted in Python, Python - Advanced

Leave a Reply