Skip to content

Commit 4901620

Browse files
committed
Fix dangling references to random_in_unit_sphere()
Resolves #1637
1 parent e890e6d commit 4901620

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Change Log / Ray Tracing in One Weekend
44
# v4.0.2 (in progress)
55

66
### Common
7+
- Fix -- Fixed some dangling references to `random_in_unit_sphere()` (#1637)
78

89
### In One Weekend
910
- Fix -- Fix equation for refracted rays of non-unit length (#1644)

books/RayTracingInOneWeekend.html

+5-5
Original file line numberDiff line numberDiff line change
@@ -2344,7 +2344,7 @@
23442344
}
23452345
}
23462346
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2347-
[Listing [random-in-unit-sphere]: <kbd>[vec3.h]</kbd> The random_unit_vector() function, version one]
2347+
[Listing [random-unit-vector-1]: <kbd>[vec3.h]</kbd> The random_unit_vector() function, version one]
23482348

23492349
</div>
23502350

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

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

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

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

40474047
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
40484048
...

books/RayTracingTheRestOfYourLife.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,20 @@
6969
will take to get there. The classic example of a Las Vegas algorithm is the _quicksort_ sorting
7070
algorithm. The quicksort algorithm will always complete with a fully sorted list, but, the time it
7171
takes to complete is random. Another good example of a Las Vegas algorithm is the code that we use
72-
to pick a random point in a unit sphere:
72+
to pick a random point in a unit disk:
7373

7474
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
75-
inline vec3 random_in_unit_sphere() {
75+
inline vec3 random_in_unit_disk() {
7676
while (true) {
77-
auto p = vec3::random(-1,1);
77+
auto p = vec3(random_double(-1,1), random_double(-1,1), 0);
7878
if (p.length_squared() < 1)
7979
return p;
8080
}
8181
}
8282
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8383
[Listing [las-vegas-algo]: <kbd>[vec3.h]</kbd> A Las Vegas algorithm]
8484

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

0 commit comments

Comments
 (0)