CraigTreptow

CraigTreptow

The Ray Tracer Challenge: Chapter 7 - Calculating pixel size

Hi. I’m working on this test:

Scenario ​: The pixel size for a horizontal canvas
Given ​ c ← camera(200, 125, π/2)
Then ​ c.pixel_size = 0.01

I’m doing this in Haskell, so I’m pulling the following from a Haskell REPL prompt that is doing the same calculations as my code:

> hs = 200
> vs = 125
> fov = (pi/2)
> 1.5707963267948966

> radians = (fov/2) * (pi/180)
> 1.3707783890401887e-2         ==> (0.013707783)
> ar = (fromIntegral hs) / (fromIntegral vs)
> 1.6
> hv = tan radians
> 1.3708642534394055e-2         ==> (0.01370864253)
> hw = calcHalfWidth ar hv
> 1.3708642534394055e-2         ==> (0.01370864253)
> (hw * 2) / (fromIntegral hs)  ==> (0.02741728506) / 200
1.3708642534394054e-4           ==> (0.00013708642)

I’m trying to track down where this is going wrong, and every time I double check my calculations, I convince myself that they are correct, even though I’m off by so much.

Does anybody see any obvious issues?

Marked As Solved

CraigTreptow

CraigTreptow

I have confirmed the book uses only radians for angles, so after undoing the radian conversion, my answer was actually 9.999999999999998e-3. or 0.009999999. So, I had it all along, but just couldn’t see it.

That’s what a night of sleep and a helpful stranger gets you. :wink:

Also Liked

NobbZ

NobbZ

You are not off. 0.000137 is just another way to write 1.37e-4.

You have to read it as 1.37 * 10 ^ (-4).

It is called scientific notation.

CraigTreptow

CraigTreptow

Sorry, I wasn’t clear. That last calculation is the pixel size, which should equal 0.01. I was just showing the non-scientific notation values by adding the ‘==> (some number)’

Where Next?

Popular Pragmatic Bookshelf topics Top

jeffmcompsci
Title: Design and Build Great Web APIs - typo “https://company-atk.herokuapp.com/2258ie4t68jv” (page 19, third bullet in URL list) Typo:...
New
jamis
The following is cross-posted from the original Ray Tracer Challenge forum, from a post by garfieldnate. I’m cross-posting it so that the...
New
simonpeter
When I try the command to create a pair of migration files I get an error. user=> (create-migration "guestbook") Execution error (Ill...
New
herminiotorres
Hi @Margaret , On page VII the book tells us the example and snippets will be all using Elixir version 1.11 But on page 3 almost the en...
New
herminiotorres
Hi! I know not the intentions behind this narrative when called, on page XI: mount() |> handle_event() |> 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
leba0495
Hello! Thanks for the great book. I was attempting the Trie (chap 17) exercises and for number 4 the solution provided for the autocorre...
New
patoncrispy
I’m new to Rust and am using this book to learn more as well as to feed my interest in game dev. I’ve just finished the flappy dragon exa...
New
brunogirin
When I run the coverage example to report on missing lines, I get: pytest --cov=cards --report=term-missing ch7 ERROR: usage: pytest [op...
New
bjnord
Hello @herbert ! Trying to get the very first “Hello, Bracket Terminal!" example to run (p. 53). I develop on an Amazon EC2 instance runn...
New

Other popular topics Top

ohm
Which, if any, games do you play? On what platform? I just bought (and completed) Minecraft Dungeons for my Nintendo Switch. Other than ...
New
PragmaticBookshelf
A PragProg Hero’s Journey with Brian P. Hogan @bphogan Have you ever worried that your only legacy will be in the form of legacy...
New
siddhant3030
I’m thinking of buying a monitor that I can rotate to use as a vertical monitor? Also, I want to know if someone is using it for program...
New
New
Exadra37
On modern versions of macOS, you simply can’t power on your computer, launch a text editor or eBook reader, and write or read, without a ...
New
AstonJ
Seems like a lot of people caught it - just wondered whether any of you did? As far as I know I didn’t, but it wouldn’t surprise me if I...
New
New
AstonJ
If you want a quick and easy way to block any website on your Mac using Little Snitch simply… File > New Rule: And select Deny, O...
New
First poster: bot
Large Language Models like ChatGPT say The Darnedest Things. The Errors They MakeWhy We Need to Document Them, and What We Have Decided ...
New
PragmaticBookshelf
Author Spotlight: Sophie DeBenedetto @SophieDeBenedetto The days of the traditional request-response web application are long gone, b...
New

Sub Categories: