You are reading a post from a multi-part series of articles
- Ray Tracer in Python (Part 1) - Show Notes of "Points in 3D Space"
- Ray Tracer in Python (Part 2) - Show Notes of "Revealing the True Colors"
- Ray Tracer in Python (Part 3) - Show Notes of "3D Balls in 2D Space"
- Ray Tracer in Python (Part 4) - Show Notes of "Let there be light"
- Ray Tracer in Python - Show Notes of "Ray Tracing a Coronavirus"
- Ray Tracer in Python (Part 5) - Show Notes of "Some Light Reflections"
- Ray Tracer in Python (Part 6) - Show Notes of "Firing All Cores"
Graphics is what made Mathematics enjoyable for me. I first heard of trigonometric functions like sine and cosine when I read GW-BASIC manual. Geometry was easy to visualize with the rudimentary graphics of LINE and CIRCLE statements. While I could see many struggle with Mathematics, I always found it interesting.
So my challenge was to make this math-heavy episode interesting so that you see how I see it. I needed to give personalities to Ray and Sphere before I could show their intersection formula. This needed a lot of illustration and animation work. But I believe the end result was worth it.
This time there is a lot of furious typing and less talking because of the number of lines entered in this part. I did not want to fast forward code writing segments because it doesn’t help the learners. In any case, YouTube can speed up videos if you choose to.
These are the topics we will cover in this episode:
- Why meshes in movies and spheres in raytracers
- Simplified ray-tracing
- Ray-sphere intersection
- Aspect Ratio Corrections
- First sub-problem: 3D Balls in 2D Space
- Coding the solution
- Hex colors
- Classes for Engine, Ray, Sphere, etc.
- Rendering Algorithm
Here is the video:
Code for part three is tagged on the Puray Github project
Bonus (Traffic Lights) Code is available for download.
Books and articles that can help understand this part:
Real-Time Collision Detection Great introduction and overview of different intersection and collision algorithms
Line–sphere intersection - Wikipedia Wikipedia page with the mathematical derivation of the formula we have used.
Note: References may contain affiliate links