For detailed explaination, please visit : Donut Math
Overview Strategy:
2 - Create a donut, which is a 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
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}