why you NEED math for programming
Chapters9
Introduction to rendering a donut and recognizing that the project started as a simple visual in the terminal.
Math isn’t just theory—it unlocks real, visible tricks in programming, from rendering a donut in your terminal to tackling graphics, ML, and cryptography.
Summary
Joma Tech walks you through why math matters in programming by turning a playful donut-rendering demo into a case study. He starts by showing a simple donut that somehow appears in a terminal, then links that toy example to core concepts: projecting 3D coordinates, rotating around axes, and shading with a light-facing dot product. The author points out that the math behind a solid of revolution and the rotation matrices are what make the donut (or a cube) manipulable in 3D space. He explains how to map 3D points to a 2D screen and use surface normals and lighting to choose characters that represent brightness. Beyond the demo, Joma Tech argues that math is a practical tool for more advanced domains like computer graphics, machine learning, and cryptography, and he notes that even if you only use it 1% of the time, that edge can separate great programmers from average ones. The talk closes with a nod to Andy Sloan’s original work and a plug for Joma Class, highlighting the value of structured learning with visual explanations. The overall message: strengthen your math muscle now, because when the moment comes, it makes all the difference in your coding career.
Key Takeaways
- Understanding a solid of revolution allows you to model a donut by rotating a circle around an axis, laying the groundwork for 3D rendering concepts.
- Rotation matrices around the x, y, and z axes enable you to animate 3D objects like a donut or a cube, transforming coordinates in space.
- 3D-to-2D projection on a terminal screen can be achieved by mapping each 3D point to a character, effectively creating a pixel-like display.
- Lighting is computed via the dot product of surface normals and light direction, determining brightness and therefore which terminal character to show.
- Math is essential not only for graphics but also as a foundational skill for machine learning and cryptography, where precise math knowledge yields practical advantages.
- Even if you only need math 1% of the time, that knowledge can distinguish a great programmer from an average one.
- A classic example of math in programming is adapting a donut to change size, rotation, or even become a different shape like a cube.
Who Is This For?
Essential viewing for programmers curious about the practical value of math in coding, especially those interested in graphics, ML, or cryptography. It shows concrete techniques you can actually experiment with today.
Notable Quotes
"it's a donut it's incredible isn't it"
—Illustrates the playful result of applying math to render a 3D shape in a terminal.
"why is math important for programming well it's because even if 99 of the time you won't need it there's a one percent chance that you might"
—Core rationale for investing in math as a programmer.
"this is the formula to create the circle centered at r2 with radius r1"
—Shows the concrete math steps used to build the donut model.
"the idea and code were originally from the amazing andy sloan"
—Credits the original inspiration for the demo.
Questions This Video Answers
- How does rotating a circle around an axis create a donut shape in 3D graphics?
- What are rotation matrices and how are they applied to 3D coordinates?
- Why is the dot product used for lighting calculations in computer graphics?
- Can math actually improve performance in programming beyond graphics?
- What examples connect math concepts to real-world programming skills?
Math in programming3D graphics mathRotation matricesDot product lightingSolid of revolution3D to 2D projectionTerminal renderingAndy SloanJoma Class
Full Transcript
[Music] okay jesus nope not jesus it's just me what the hell is going on oh yeah um yeah i was working on this program and um yeah i i think i figured it out i think i got the formula so basically if you merge the projection equation wait wait wait what are you doing oh right um okay let let me just show you let me just finish up real quick ready wait i i i don't follow this is that it's a donut it's incredible isn't it so so all this just to render a donut on your terminal what the [ __ ] thanks for watching the idea and code were originally from the amazing andy sloan where he was able to code this whole program and see and made the code itself look like a donut he has an article explaining how the code works which i'll link in the description so why is math important for programming well it's because even if 99 of the time you won't need it there's a one percent chance that you might and it's in those moments that separate out a great programmer from average ones and if you do know your math you'll know how to modify this donut to increase the size change the rotation or even make a cube instead also if you want to do computer graphics machine learning or cryptography you're gonna need math so might as well get good at it as you did for programming anyway back to the donut how do we write this program well first you have to create a donut which is essentially a solid of revolution where we have a circle that rotates around the y-axis which will make a donut aka a tourist this is the formula to create the circle centered at r2 with radius r1 and this is the rotation matrix to rotate this circle around the y axis so when we combine them we get the coordinates of every point on your donut now that we have a donut shut up i know this is a bagel now that we have a donut we want to rotate it around the x and z axis so it looks cool all flying and stuff we can do that by multiplying our donut coordinates with these two rotation matrices now we have to map this 3d flying donut onto a 2d screen which will become our terminal so each character on the terminal will be a pixel on the screen to figure out how to shade our donut we calculate the dot product of the surface normal and the direction of the light so as you can see when the normal points this way it's way brighter and when it points that way it's way darker so the dot product will tell us how light or dark it is we take the result of the dot product and map it into these characters from darkest to brightest and lastly we draw that on our terminal and voila if you like the way i teach you can check out my new course on data structures and algorithms where i use easy to understand animations to explain these concepts the first 100 people to sign up for joma class will get 15 percent off joma class
More from Joma Tech
Get daily recaps from
Joma Tech
AI-powered summaries delivered to your inbox. Save hours every week while staying fully informed.



