# Intersecting spheres

The first piece of actual ray tracing: calculating the intersection between a ray and a sphere. To find the intersections, we need to solve the quadratic equation of the sphere being equal to the linear equation of the ray. The interpretation of imaginary roots is that the ray does not intersect the sphere.

Combining the sphere equation \(\|\dot{x} - \dot{C}\|^2 = R^2\) and the line equation \(\dot{x} = \dot{O} + t\overrightarrow{D}\) we get:

\[\|\dot{O} + t\overrightarrow{D} - \dot{C}\|^2 = R^2\]Since the unit sphere is centered at \(\dot{0}\) and its radius is \(1\), the equation can be simplified:

\[\|\dot{O} + t\overrightarrow{D}\|^2 - 1 = 0\]*On another pomodorian side note, actually taking the 5 minute breaks every 25 minutes is really hard, but I’m starting to see how it might be worth it, by not falling into a hyperfocus trance until suddenly SO HANGRY AND WHERE DID THE DAY GO?!*

## Next related

### Surface normals

Today brings normal vectors into the mix, a critical component for shading computations; the normal vector of a surface at the point where it was hit by a ray, to be precise. Because the normal depends on the hit position on the surface, and we’ll need that too, we keep that around as well.

## Previous related

### Basic data types

Alright, the first push to the [github repo] is complete. Starting out small with just the basic data types that will be at the core of everything, and some tolerance equality operators for comparisons.

### Devember again

This one snuck up on me faster than anticipated, but here we go.

### Light and Magic

Made some refinements to lighting. Originially there was only a point light without distance falloff, which is not an accurate light model in any case. The light inside the room lights the entire world, all the way to the horizon.