RayTracing / raytracing.github.io

Main Web Site (Online Books)
https://raytracing.github.io/
Creative Commons Zero v1.0 Universal
8.77k stars 862 forks source link

Listing 3.15: Typo in f(double d) function #1310

Open hollasch opened 12 months ago

hollasch commented 12 months ago

Benny Tsang writes:

(Book 3) Section 3.7, Listing 15, typo in the f(double d) function, the `8.0' should be inside pow(8.0*d, 1./3.).

hollasch commented 7 months ago

I'm not sure I understand this. @trevordblack ?

Interestingly, 8.0 * pow(d, 1.0/3.0) yields the same result as pow(8.0 * d, 1.0/3.0).

hollasch commented 7 months ago

Wait, what the heck is going on here?

$$ x = \text{something} $$

$$ sum = \frac{x^2}{pdf(x)} = \frac{x^2}{3/8 x^2} = 8/3 $$

So, yeah. This "always returns the exact answer." _Regardless of the function f._ Given all this, why did we bother deriving the function f?

hollasch commented 7 months ago

For some reason I had a hard time grokking Benny's original inverse assertion, but here's the derivation:

$$ P(x) = f = \frac{x^3}{8} $$

$$ 8f = x^3 $$

$$ (8f)^\frac{1}{3} = x $$

Also note that the original books had the (correct?) equation: x = pow(8*drand48(), 1./3.).

petershirley commented 7 months ago

I had to go reread this-- I am thinking the motivation in the text isn't super. In the never happens case where you know the integral's solution already you can sample it perfectly. We can do this in this artificial example. I want to sleep on this. Should we even have it? Steve I am confused about today's note-- I think it should be a times? But should we get rid of this example becuase it never happens in real life that exact sampling is possible?

trevordblack commented 7 months ago

I had a hard time rewritting this.

I don't remember exactly what I was trying to say, but it was something in the realm that "If your random generator function is a delta function with the correct answer, then you don't need to sample multiple times"

But I never found the time to clean it up