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)’

Popular Pragmatic Bookshelf topics Top

kuroneko
Whilst the author has been careful to provide exact results for the tests elsewhere in the book (such as surds with the transformation te...
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
belgoros
Following the steps described in Chapter 6 of the book, I’m stuck with running the migration as described on page 84: bundle exec sequel...
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
JohnS
I can’t setup the Rails source code. This happens in a working directory containing multiple (postgres) Rails apps. With: ruby-3.0.0 s...
New
herminiotorres
Hi! I know not the intentions behind this narrative when called, on page XI: mount() |> handle_event() |> render() but the correc...
New
brunogirin
When running tox for the first time, I got the following error: ERROR: InterpreterNotFound: python3.10 I realised that I was running ...
New
oaklandgit
Hi, I completed chapter 6 but am getting the following error when running: thread 'main' panicked at 'Failed to load texture: IoError(O...
New
dsmith42
Hey there, I’m enjoying this book and have learned a few things alredayd. However, in Chapter 4 I believe we are meant to see the “>...
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

wolf4earth
@AstonJ prompted me to open this topic after I mentioned in the lockdown thread how I started to do a lot more for my fitness. https://f...
New
Exadra37
Please tell us what is your preferred monitor setup for programming(not gaming) and why you have chosen it. Does your monitor have eye p...
New
dasdom
No chair. I have a standing desk. This post was split into a dedicated thread from our thread about chairs :slight_smile:
New
PragmaticBookshelf
Rust is an exciting new programming language combining the power of C with memory safety, fearless concurrency, and productivity boosters...
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
I ended up cancelling my Moonlander order as I think it’s just going to be a bit too bulky for me. I think the Planck and the Preonic (o...
New
Exadra37
I am asking for any distro that only has the bare-bones to be able to get a shell in the server and then just install the packages as we ...
New
AstonJ
If you get Can't find emacs in your PATH when trying to install Doom Emacs on your Mac you… just… need to install Emacs first! :lol: bre...
New
PragmaticBookshelf
Author Spotlight: Bruce Tate @redrapids Programming languages always emerge out of need, and if that’s not always true, they’re defin...
New
PragmaticBookshelf
A Ruby-Centric Chat with Noel Rappin @noelrappin Once you start noodling around with Ruby you quickly figure out, as Noel Rappi...
New