Operations

Now that you have these tuples, you’re faced with the question of how to use them. Ultimately, these will be the bedrock of your ray tracer—they’ll crop up in calculations everywhere, from computing the intersection of a ray with objects in your scene to figuring out how a particular point on a surface ought to be shaded. But to plug these vectors and points into your calculations, you need to implement a few basic operations on them.

Let’s start with some familiar operations from arithmetic.

images/aside-icons/tip.png

If you haven’t already, take a minute to write a function that will compare two tuples for equality. It’ll save you some duplication! As you ...

Get The Ray Tracer Challenge now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.