The Ray Tracer Challenge: "Computing the normal on a transformed sphere" ebook test

@jamis

I ran into this too. I’m also using a fluent interface and transcribed the test wrong. Thank you both for helping me understand what’s going wrong.

It’s a bit odd that the rotation is even part of the transformation since it’s clearly a no-op when applied to the unit sphere centered on the object origin. After fixing my test transcription bug, I came up with an alternative test where each part of the transform has a meaningful impact:

Scenario: Given the normal on a transformed sphere
Given s <- sphere()
And m <- scaling(1, 0.5, 1) * shearing(1, 0, 0, 0, 0, 0)
And set_transform(s, m)
When n <- normal_at(s, point(0, sqrt(2)/2, sqrt(2)/2))
Then n = vector(-0.24077171, 0.96308684, -0.120385855)

But beware, I have not verified the computation beyond using my implementation to get the normal vector. Also, note if you’re using a fluent interface for your transforms, the identity should be followed by shearing.

1 Like