This project implements a rotating 3D torus (donut) displayed in the console using C++ and Windows API.
- Windows operating system
- C++ compiler (e.g., MSVC, MinGW)
-
Clone the repository:
git clone https://github.com/yourusername/donut-cpp.git cd donut-cpp
-
Compile the code:
g++ -o donut main.cpp -lgdi32
-
Run compiled file in a teminal window:
./donut.exe
The 3D torus (donut) visualization involves several mathematical concepts:
A torus can be described parametrically with two angles, ( \theta ) and ( \phi ), representing the position on the torus:
Here:
-
$R$ is the major radius (distance from the center of the tube to the center of the torus). -
$r$ is the minor radius (radius of the tube).
To rotate the torus, we use rotation matrices for the X, Y, and Z axes. These matrices allow us to rotate points in 3D space.
To display the 3D torus on a 2D console, we project 3D points onto a 2D plane using the perspective projection formula:
Here,
The torus rotation and drawing are controlled to achieve a consistent frame rate. This involves calculating the time taken to process each frame and adjusting the sleep time to maintain a stable frame rate, typically 60 frames per second.
By combining these mathematical concepts, we achieve a rotating 3D torus that is projected and visualized in the console.
Checkout my other projects at my portfolio