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 Prag Prog topics Top

iPaul
page 37 ANTLRInputStream input = new ANTLRInputStream(is); as of ANTLR 4 .8 should be: CharStream stream = CharStreams.fromStream(i...
New
Razor54672
The answer to 3rd Problem of Chapter 5 (Making Choices) of “Practical Programming, Third Edition” seems incorrect in the given answer ke...
New
jesse050717
Title: Web Development with Clojure, Third Edition, pg 116 Hi - I just started chapter 5 and I am stuck on page 116 while trying to star...
New
yulkin
your book suggests to use Image.toByteData() to convert image to bytes, however I get the following error: "the getter ‘toByteData’ isn’t...
New
AndyDavis3416
@noelrappin Running the webpack dev server, I receive the following warning: ERROR in tsconfig.json TS18003: No inputs were found in c...
New
fynn
This is as much a suggestion as a question, as a note for others. Locally the SGP30 wasn’t available, so I ordered a SGP40. On page 53, ...
New
jskubick
I think I might have found a problem involving SwitchCompat, thumbTint, and trackTint. As entered, the SwitchCompat changes color to hol...
New
jonmac
The allprojects block listed on page 245 produces the following error when syncing gradle: “org.gradle.api.GradleScriptException: A prob...
New
tkhobbes
After some hassle, I was able to finally run bin/setup, now I have started the rails server but I get this error message right when I vis...
New
a.zampa
@mfazio23 I’m following the indications of the book and arriver ad chapter 10, but the app cannot be compiled due to an error in the Bas...
New

Other popular topics Top

Devtalk
Hello Devtalk World! Please let us know a little about who you are and where you’re from :nerd_face:
New
AstonJ
A thread that every forum needs! Simply post a link to a track on YouTube (or SoundCloud or Vimeo amongst others!) on a separate line an...
New
Exadra37
I am a Linux user since 2012, more or less, and I always use Ubuntu on my computers, and my last 2 laptops have been used Thinkpads, wher...
New
PragmaticBookshelf
“Finding the Boundaries” Hero’s Journey with Noel Rappin @noelrappin Even when you’re ultimately right about what the future ho...
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 are experiencing Rails console using 100% CPU on your dev machine, then updating your development and test gems might fix the issu...
New
PragmaticBookshelf
Rails 7 completely redefines what it means to produce fantastic user experiences and provides a way to achieve all the benefits of single...
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: Sophie DeBenedetto @SophieDeBenedetto The days of the traditional request-response web application are long gone, b...
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

Latest in PragProg

View all threads ❯