lirux

lirux

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

Hi Jamis,
I think there’s an issue with a test on chapter 6. I own the ebook, version P1.0 Feb. 2019.
This test doesn’t pass for me:

But removing the rotation_z transformation the test will pass.
I suppose that a previous errata updated the transformation matrix m but not the resulting normal vector n.
This is my normal with the rotation_z:
x: -0.4149850363522584, y: 0.8620719608670172, z: -0.29089405956569586

Hope it helps!

Marked As Solved

jdunlap

jdunlap

I think that I see the problem. You are applying the transformations in the wrong order. You are not rotating an ellipsoid in that test at all. Transformations are applied to a point in the opposite direction of what they appear, so in this test, the sphere is rotated and then scaled.

Perhaps this image will help to illustrate.

The blue ellipsoid is generated using the the order in the test (Scaling * Rotation) while the pinkish one is generated with the opposite order (Rotation * Scaling). This demonstrates that you are rotating a sphere in the test and then squishing it to an ellipsoid, not the other way around.

I agree with you that the other way would definitely rotate the normal, but I don’t believe it would in this case. Perhaps maybe Jamis intended for the second case when he made this correction, but inadvertently used this one which has no effect with or without the rotation.

Also Liked

lirux

lirux

Yes, you are right.
In my code I choose a fluent API, in witch the order of the matrix multiplications is reversed behind the scene.
So instead of using scaling(1, 0.5, 1).rotation_z(pi/5) (that equals to m = rotation_z * scaling) I should have written the opposite: rotation_z(pi/5).scaling(1, 0.5, 1).

Thank you for your help!

jdunlap

jdunlap

I don’t think that you’re right about this. Mine passes all tests with the z-axis rotation in. It also passes without, but that actually makes sense. First, we would rotate the original point into world space. We would then find the vector and then rotate it back to world space, causing it to point in the same direction as before. Without the rotation, we just don’t do and then undo the rotation. The rotation in this test does pretty much nothing because we already have the intersection point. It would be very different (in later chapters) when we cast a ray from world space in a direction to intersect the sphere. Then, it will make quite a bit of difference.

Please correct me if my logic is off, and I have not done the math by hand to verify all of this, but it makes logical sense to me. And my tests are passing without making any changes like you recommend.

mx00s

mx00s

@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.

Popular Prag Prog topics Top

abtin
page 20: … protoc command… I had to additionally run the following go get commands in order to be able to compile protobuf code using go...
New
jimmykiang
This test is broken right out of the box… — FAIL: TestAgent (7.82s) agent_test.go:77: Error Trace: agent_test.go:77 agent_test.go:...
New
johnp
Running the examples in chapter 5 c under pytest 5.4.1 causes an AttributeError: ‘module’ object has no attribute ‘config’. In particula...
New
simonpeter
When I try the command to create a pair of migration files I get an error. user=&gt; (create-migration "guestbook") Execution error (Ill...
New
herminiotorres
Hi! I know not the intentions behind this narrative when called, on page XI: mount() |&gt; handle_event() |&gt; render() but the correc...
New
conradwt
First, the code resources: Page 237: rumbl_umbrella/apps/rumbl/mix.exs Note: That this file is missing. Page 238: rumbl_umbrella/app...
New
cro
I am working on the “Your Turn” for chapter one and building out the restart button talked about on page 27. It recommends looking into ...
New
brian-m-ops
#book-python-testing-with-pytest-second-edition Hi. Thanks for writing the book. I am just learning so this might just of been an issue ...
New
nicoatridge
Hi, I have just acquired Michael Fazio’s “Kotlin and Android Development” to learn about game programming for Android. I have a game in p...
New
hazardco
On page 78 the following code appears: &lt;%= link_to ‘Destroy’, product, class: ‘hover:underline’, method: :delete, data: { confirm...
New

Other popular topics Top

PragmaticStudio
Let’s get real. As in really knowing—clearly and practically—what’s up with Phoenix LiveView. What is it? How does it work? What can I ...
New
AstonJ
You might be thinking we should just ask who’s not using VSCode :joy: however there are some new additions in the space that might give V...
New
AstonJ
I’ve been hearing quite a lot of comments relating to the sound of a keyboard, with one of the most desirable of these called ‘thock’, he...
New
foxtrottwist
Here’s our thread for the Keyboardio Atreus. It is a mechanical keyboard based on and a slight update of the original Atreus (Keyboardio ...
New
gagan7995
API 4 Path: /user/following/ Method: GET Description: Returns the list of all names of people whom the user follows Response [ { ...
New
rustkas
Intensively researching Erlang books and additional resources on it, I have found that the topic of using Regular Expressions is either c...
New
PragmaticBookshelf
Author Spotlight James Stanier @jstanier James Stanier, author of Effective Remote Work , discusses how to rethink the office as we e...
New
PragmaticBookshelf
Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
New
AstonJ
Was just curious to see if any were around, found this one: I got 51/100: Not sure if it was meant to buy I am sure at times the b...
New
PragmaticBookshelf
Author Spotlight: Karl Stolley @karlstolley Logic! Rhetoric! Prag! Wow, what a combination. In this spotlight, we sit down with Karl ...
New

Latest in PragProg

View all threads ❯