Skip to content

Commit 90dccd3

Browse files
committed
Math notation update: book 2
Points are uppercase bold, vectors are lowercase bold, no barb.
1 parent b4ffe6f commit 90dccd3

File tree

1 file changed

+51
-50
lines changed

1 file changed

+51
-50
lines changed

books/RayTracingTheNextWeek.html

Lines changed: 51 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,9 @@
409409
</div>
410410

411411
<div class='together'>
412-
Note that the blue and red bounding volumes are contained in the purple one, but they might
413-
overlap, and they are not ordered -- they are just both inside. So the tree shown on the right has
414-
no concept of ordering in the left and right children; they are simply inside. The code would be:
412+
Note that the blue and red bounding volumes are contained in the purple one, but they might overlap,
413+
and they are not ordered -- they are just both inside. So the tree shown on the right has no concept
414+
of ordering in the left and right children; they are simply inside. The code would be:
415415

416416
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
417417
if (hits purple)
@@ -439,9 +439,9 @@
439439

440440
<div class='together'>
441441
Most people use the “slab” method. This is based on the observation that an n-dimensional AABB is
442-
just the intersection of n axis-aligned intervals, often called “slabs” An interval is just
443-
the points between two endpoints, _e.g._, $x$ such that $3 < x < 5$, or more succinctly $x$ in
444-
$(3,5)$. In 2D, two intervals overlapping makes a 2D AABB (a rectangle):
442+
just the intersection of n axis-aligned intervals, often called “slabs” An interval is just the
443+
points between two endpoints, _e.g._, $x$ such that $3 < x < 5$, or more succinctly $x$ in $(3,5)$.
444+
In 2D, two intervals overlapping makes a 2D AABB (a rectangle):
445445

446446
![Figure [2daabb]: 2D axis-aligned bounding box](../images/fig.2daabb.jpg)
447447

@@ -459,29 +459,28 @@
459459
<div class='together'>
460460
In 3D, those boundaries are planes. The equations for the planes are $x = x_0$, and $x = x_1$. Where
461461
does the ray hit that plane? Recall that the ray can be thought of as just a function that given a
462-
$t$ returns a location $p(t)$:
462+
$t$ returns a location $\mathbf{P}(t)$:
463463

464-
$$ p(t) = \mathbf{a} + t \vec{\mathbf{b}} $$
464+
$$ \mathbf{P}(t) = \mathbf{A} + t \mathbf{b} $$
465465
</div>
466466

467467
<div class='together'>
468-
That equation applies to all three of the x/y/z coordinates. For example,
469-
$x(t) = \mathbf{a}_x + t \vec{\mathbf{b}}_x$. This ray hits the plane $x = x_0$ at the $t$ that
470-
satisfies this equation:
468+
That equation applies to all three of the x/y/z coordinates. For example, $x(t) = A_x + t b_x$. This
469+
ray hits the plane $x = x_0$ at the $t$ that satisfies this equation:
471470

472-
$$ x_0 = \mathbf{a}_x + t_0 \vec{\mathbf{b}}_x $$
471+
$$ x_0 = A_x + t_0 b_x $$
473472
</div>
474473

475474
<div class='together'>
476475
Thus $t$ at that hitpoint is:
477476

478-
$$ t_0 = \frac{x_0 - \mathbf{a}_x}{\vec{\mathbf{b}}_x} $$
477+
$$ t_0 = \frac{x_0 - A_x}{b_x} $$
479478
</div>
480479

481480
<div class='together'>
482481
We get the similar expression for $x_1$:
483482

484-
$$ t_1 = \frac{x_1 - \mathbf{a}_x}{\vec{\mathbf{b}}_x} $$
483+
$$ t_1 = \frac{x_1 - A_x}{b_x} $$
485484
</div>
486485

487486
<div class='together'>
@@ -526,31 +525,30 @@
526525
as long as we make it reasonably fast, so let’s go for simplest, which is often fastest anyway!
527526
First let’s look at computing the intervals:
528527

529-
$$ t_{x0} = \frac{x_0 - \mathbf{a}_x}{\vec{\mathbf{b}}_x} $$
530-
$$ t_{x1} = \frac{x_1 - \mathbf{a}_x}{\vec{\mathbf{b}}_x} $$
528+
$$ t_{x0} = \frac{x_0 - A_x}{b_x} $$
529+
$$ t_{x1} = \frac{x_1 - A_x}{b_x} $$
531530
</div>
532531

533532
<div class='together'>
534-
One troublesome thing is that perfectly valid rays will have $\vec{\mathbf{b}}_x = 0$, causing
535-
division by zero. Some of those rays are inside the slab, and some are not. Also, the zero will have
536-
a ± sign under IEEE floating point. The good news for $\vec{\mathbf{b}}_x = 0$ is that $t_{x0}$ and
537-
$t_{x1}$ will both be +∞ or both be -∞ if not between $x_0$ and $x_1$. So, using min and max should
538-
get us the right answers:
533+
One troublesome thing is that perfectly valid rays will have $b_x = 0$, causing division by zero.
534+
Some of those rays are inside the slab, and some are not. Also, the zero will have a ± sign under
535+
IEEE floating point. The good news for $b_x = 0$ is that $t_{x0}$ and $t_{x1}$ will both be +∞ or
536+
both be -∞ if not between $x_0$ and $x_1$. So, using min and max should get us the right answers:
539537

540538
$$ t_{x0} = \min(
541-
\frac{x_0 - \mathbf{a}_x}{\vec{\mathbf{b}}_x},
542-
\frac{x_1 - \mathbf{a}_x}{\vec{\mathbf{b}}_x})
539+
\frac{x_0 - A_x}{b_x},
540+
\frac{x_1 - A_x}{b_x})
543541
$$
544542

545543
$$ t_{x1} = \max(
546-
\frac{x_0 - \mathbf{a}_x}{\vec{\mathbf{b}}_x},
547-
\frac{x_1 - \mathbf{a}_x}{\vec{\mathbf{b}}_x})
544+
\frac{x_0 - A_x}{b_x},
545+
\frac{x_1 - A_x}{b_x})
548546
$$
549547
</div>
550548

551-
The remaining troublesome case if we do that is if $\vec{\mathbf{b}}_x = 0$ and either
552-
$x_0 - \mathbf{a}_x = 0$ or $x_1 - \mathbf{a}_x = 0$ so we get a `NaN`. In that case we can probably
553-
accept either hit or no hit answer, but we’ll revisit that later.
549+
The remaining troublesome case if we do that is if $b_x = 0$ and either $x_0 - A_x = 0$ or $x_1 -
550+
A_x = 0$ so we get a `NaN`. In that case we can probably accept either hit or no hit answer, but
551+
we’ll revisit that later.
554552

555553
<div class='together'>
556554
Now, let’s look at that overlap function. Suppose we can assume the intervals are not reversed (so
@@ -809,15 +807,15 @@
809807
but that is for speed not correctness. I’ll choose the middle ground, and at each node split the
810808
list along one axis. I’ll go for simplicity:
811809

812-
1. randomly choose an axis
813-
2. sort the primitives using library qsort
814-
3. put half in each subtree
810+
1. randomly choose an axis
811+
2. sort the primitives using library qsort
812+
3. put half in each subtree
815813

816814
</div>
817815

818816
<div class='together'>
819817
When the list coming in is two elements, I put one in each subtree and end the recursion. The
820-
traverse algorithm should be smooth and not have to check for null pointers, so if I just have one
818+
traversal algorithm should be smooth and not have to check for null pointers, so if I just have one
821819
element I duplicate it in each subtree. Checking explicitly for three elements and just following
822820
one recursion would probably help a little, but I figure the whole method will get optimized later.
823821
This yields:
@@ -1228,8 +1226,7 @@
12281226
</div>
12291227

12301228
<div class='together'>
1231-
Now if we create an actual texture that takes these floats between 0 and 1 and creates grey
1232-
colors:
1229+
Now if we create an actual texture that takes these floats between 0 and 1 and creates grey colors:
12331230

12341231
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
12351232
#include "perlin.h"
@@ -1710,7 +1707,7 @@
17101707
</div>
17111708

17121709
<div class='together'>
1713-
The $atan2$ returns in the range $-\pi$ to $\pi$ so we need to take a little care there.
1710+
The $atan2$ returns values in the range $-\pi$ to $\pi$, so we need to take a little care there.
17141711
The $\theta$ is more straightforward:
17151712

17161713
$$ \theta = \text{asin}(z) $$
@@ -1746,9 +1743,9 @@
17461743
Storing Texture Image Data
17471744
---------------------------
17481745
Now we also need to create a texture class that holds an image. I am going to use my favorite image
1749-
utility [stb_image][]. It reads in an image into a big array of unsigned char. These are just
1750-
packed RGBs that each range 0..255 (black to full white). The `image_texture` class uses the
1751-
resulting image data.
1746+
utility [stb_image][]. It reads in an image into a big array of unsigned char. These are just packed
1747+
RGBs with each component in the range [0,255] (black to full white). The `image_texture` class uses
1748+
the resulting image data.
17521749

17531750
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
17541751
#include "rtweekend.h"
@@ -1813,9 +1810,9 @@
18131810
[Listing [img-texture]: <kbd>[texture.h]</kbd> Image texture class]
18141811

18151812
<div class='together'>
1816-
The representation of a packed array in that order is pretty standard. Thankfully, the
1817-
[stb_image][] package makes that super simple -- just include the header `rtw_stb_image.h` (found in
1818-
the project source code at `src/common/rtw_stb_image.h`) in `main.h`:
1813+
The representation of a packed array in that order is pretty standard. Thankfully, the [stb_image][]
1814+
package makes that super simple -- just include the header `rtw_stb_image.h` (found in the project
1815+
source code at `src/common/rtw_stb_image.h`) in `main.h`:
18191816

18201817
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
18211818
#include "rtw_stb_image.h"
@@ -1986,18 +1983,17 @@
19861983

19871984
<div class='together'>
19881985
To determine whether a ray hits such a rectangle, we first determine where the ray hits the plane.
1989-
Recall that a ray $p(t) = \mathbf{a} + t \cdot \vec{\mathbf{b}}$ has its z component defined by
1990-
$z(t) = \mathbf{a}_z + t \cdot \vec{\mathbf{b}}_z$. Rearranging those terms we can solve for what
1991-
the t is where $z=k$.
1986+
Recall that a ray $\mathbf{P}(t) = \mathbf{A} + t \mathbf{b}$ has its z component defined by $P_z(t)
1987+
= A_z + t b_z$. Rearranging those terms we can solve for what the t is where $z=k$.
19921988

1993-
$$ t = \frac{k-\mathbf{a}_z}{\vec{\mathbf{b}}_z} $$
1989+
$$ t = \frac{k-A_z}{b_z} $$
19941990
</div>
19951991

19961992
<div class='together'>
19971993
Once we have $t$, we can plug that into the equations for $x$ and $y$:
19981994

1999-
$$ x = \mathbf{a}_x + t \cdot \vec{\mathbf{b}}_x $$
2000-
$$ y = \mathbf{a}_y + t \cdot \vec{\mathbf{b}}_y $$
1995+
$$ x = A_x + t b_x $$
1996+
$$ y = A_y + t b_y $$
20011997
</div>
20021998

20031999
It is a hit if $x_0 < x < x_1$ and $y_0 < y < y_1$.
@@ -2258,9 +2254,9 @@
22582254
This is very noisy because the light is small. But we have a problem: some of the walls are facing
22592255
the wrong way. We haven't specified that a diffuse material should behave differently on different
22602256
faces of the object, but what if the Cornell box had a different pattern on the inside and outside
2261-
walls? The rectangle objects are described such that their front faces are always in the
2262-
$(1, 0, 0)$, $(0, 1, 0)$, or $(0, 0, 1)$ directions. We need a way to switch the faces of an
2263-
object. Let’s make a hittable that does nothing but hold another hittable, and flips the face:
2257+
walls? The rectangle objects are described such that their front faces are always in the directions
2258+
$(1,0,0)$, $(0,1,0)$, or $(0,0,1)$. We need a way to switch the faces of an object. Let’s make a
2259+
hittable that does nothing but hold another hittable, and flips the face:
22642260

22652261
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
22662262
class flip_face : public hittable {
@@ -2933,6 +2929,11 @@
29332929

29342930

29352931

2932+
[Markdeep]: https://casual-effects/markdeep/
2933+
[stb_image]: https://github.com/nothings/stb
2934+
2935+
2936+
29362937
<!-- Markdeep: https://casual-effects.com/markdeep/ -->
29372938
<link rel='stylesheet' href='../style/book.css'>
29382939
<style class="fallback">body{visibility:hidden;white-space:pre;font-family:monospace}</style>

0 commit comments

Comments
 (0)