<script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

How it works?

For detailed explaination, please visit : Donut Math

Overview Strategy:

1 - How to render 3D object to 2D screen

Render 3D object on 2D screen

2 - Create a donut, which is a solid of revolution


Solid of revolution

\[ (x,y,z) = (R_2,0,0) + (R_1 \cos \theta, R_1 \sin \theta, 0) = (R_2 + R_1 \cos \theta, R_1 \sin \theta, 0) \]

We have had a circle, next step is to rotate it around y-axis by angle ϕ ( 0 < ϕ < 2π) using rotation matrix

3 - Rotate about x-axis and z-axis

1


4 - Illumination

We will set the light behind and above viewer: (0,1,-1) - light direction. To calculate illumination, we need to know the surface normal of each point. Then we can take the dot product between the point and light direction.

The fomula of surface normal for each point is similar to the above \begin{aligned} L &= \left( \begin{matrix} N_x, & N_y, & N_z \end{matrix} \right) \cdot \left( \begin{matrix} 0, & 1, & -1 \end{matrix} \right) \ &= \cos \phi \cos \theta \sin B - \cos A \cos \theta \sin \phi - \sin A \sin \theta + \cos B ( \cos A \sin \theta - \cos \theta \sin A \sin \phi) \end{aligned}