Skip to content

Commit

Permalink
Fix dangling references to random_in_unit_sphere()
Browse files Browse the repository at this point in the history
Resolves #1637
  • Loading branch information
hollasch committed Nov 15, 2024
1 parent e890e6d commit 25b8ba8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Change Log / Ray Tracing in One Weekend
# v4.0.2 (in progress)

### Common
- Fix -- Fixed some dangling references to `random_in_unit_sphere()` (#1637)

### In One Weekend
- Fix -- Fix equation for refracted rays of non-unit length (#1644)
Expand Down
10 changes: 5 additions & 5 deletions books/RayTracingInOneWeekend.html
Original file line number Diff line number Diff line change
Expand Up @@ -2344,7 +2344,7 @@
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[Listing [random-in-unit-sphere]: <kbd>[vec3.h]</kbd> The random_unit_vector() function, version one]
[Listing [random-unit-vector-1]: <kbd>[vec3.h]</kbd> The random_unit_vector() function, version one]

</div>

Expand All @@ -2369,11 +2369,11 @@
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[Listing [random-in-unit-sphere]: <kbd>[vec3.h]</kbd> The random_unit_vector() function, version one]
[Listing [random-unit-vector-2]: <kbd>[vec3.h]</kbd> The random_unit_vector() function, version two]

<div class='together'>
Now that we have a random vector on the surface of the unit sphere, we can determine if it is on the
correct hemisphere by comparing against the surface normal:
Now that we have a random unit vector, we can determine if it is on the correct hemisphere by
comparing against the surface normal:

![Figure [normal-hor]: The normal vector tells us which hemisphere we need
](../images/fig-1.13-surface-normal.jpg)
Expand Down Expand Up @@ -4042,7 +4042,7 @@

Since we'll be choosing random points from the defocus disk, we'll need a function to do that:
`random_in_unit_disk()`. This function works using the same kind of method we use in
`random_in_unit_sphere()`, just for two dimensions.
`random_unit_vector()`, just for two dimensions.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
...
Expand Down
8 changes: 4 additions & 4 deletions books/RayTracingTheRestOfYourLife.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,20 @@
will take to get there. The classic example of a Las Vegas algorithm is the _quicksort_ sorting
algorithm. The quicksort algorithm will always complete with a fully sorted list, but, the time it
takes to complete is random. Another good example of a Las Vegas algorithm is the code that we use
to pick a random point in a unit sphere:
to pick a random point in a unit disk:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
inline vec3 random_in_unit_sphere() {
inline vec3 random_in_unit_disk() {
while (true) {
auto p = vec3::random(-1,1);
auto p = vec3(random_double(-1,1), random_double(-1,1), 0);
if (p.length_squared() < 1)
return p;
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[Listing [las-vegas-algo]: <kbd>[vec3.h]</kbd> A Las Vegas algorithm]

This code will always eventually arrive at a random point in the unit sphere, but we can't say
This code will always eventually arrive at a random point in the unit disk, but we can't say
beforehand how long it'll take. It may take only 1 iteration, it may take 2, 3, 4, or even longer.
Whereas, a Monte Carlo program will give a statistical estimate of an answer, and this estimate will
get more and more accurate the longer you run it. Which means that at a certain point, we can just
Expand Down

0 comments on commit 25b8ba8

Please sign in to comment.