Skip to content

Commit dd9f764

Browse files
committed
Math cleanup pass
- Use \mathit{...} to mark variables - Use \operatorname{...} to mark operators/functions Plus additional small fixes. Resolves #839
1 parent ceb2131 commit dd9f764

File tree

3 files changed

+156
-123
lines changed

3 files changed

+156
-123
lines changed

books/RayTracingInOneWeekend.html

+11-8
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@
618618
This is commonly referred to as a _lerp_ between two values.
619619
A lerp is always of the form
620620

621-
$$ \text{blendedValue} = (1-a)\cdot\text{startValue} + a\cdot\text{endValue}, $$
621+
$$ \mathit{blendedValue} = (1-a)\cdot\mathit{startValue} + a\cdot\mathit{endValue}, $$
622622

623623
with $a$ going from zero to one.
624624

@@ -784,13 +784,16 @@
784784

785785
On the earth, this implies that the vector from the earth’s center to you points straight up. Let’s
786786
throw that into the code now, and shade it. We don’t have any lights or anything yet, so let’s just
787-
visualize the normals with a color map. A common trick used for visualizing normals (because it’s
788-
easy and somewhat intuitive to assume $\mathbf{n}$ is a unit length vector -- so each component is
789-
between -1 and 1) is to map each component to the interval from 0 to 1, and then map $(x, y, z)$ to
790-
$(\text{red}, \text{green}, \text{blue})$. For the normal, we need the hit point, not just whether
791-
we hit or not. We only have one sphere in the scene, and it's directly in front of the camera, so we
792-
won't worry about negative values of $t$ yet. We'll just assume the closest hit point
793-
(smallest $t$). These changes in the code let us compute and visualize $\mathbf{n}$:
787+
visualize the normals with a color map.
788+
A common trick used for visualizing normals (because it’s easy and somewhat intuitive to assume
789+
$\mathbf{n}$ is a unit length vector -- so each component is between -1 and 1) is to map each
790+
component to the interval from 0 to 1, and then map $(x, y, z)$ to $(\mathit{red}, \mathit{green},
791+
\mathit{blue})$.
792+
For the normal, we need the hit point, not just whether we hit or not.
793+
We only have one sphere in the scene, and it's directly in front of the camera, so we won't worry
794+
about negative values of $t$ yet.
795+
We'll just assume the closest hit point (smallest $t$).
796+
These changes in the code let us compute and visualize $\mathbf{n}$:
794797

795798
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
796799
double hit_sphere(const point3& center, double radius, const ray& r) {

books/RayTracingTheNextWeek.html

+6-6
Original file line numberDiff line numberDiff line change
@@ -1372,22 +1372,22 @@
13721372
function `atan2()`, which takes any pair of numbers proportional to sine and cosine and returns the
13731373
angle, we can pass in $x$ and $z$ (the $\sin(\theta)$ cancel) to solve for $\phi$:
13741374

1375-
$$ \phi = \text{atan2}(z, -x) $$
1375+
$$ \phi = \operatorname{atan2}(z, -x) $$
13761376

13771377
`atan2()` returns values in the range $-\pi$ to $\pi$, but they go from 0 to $\pi$, then flip to
13781378
$-\pi$ and proceed back to zero. While this is mathematically correct, we want $u$ to range from $0$
13791379
to $1$, not from $0$ to $1/2$ and then from $-1/2$ to $0$. Fortunately,
13801380

1381-
$$ \text{atan2}(a,b) = \text{atan2}(-a,-b) + \pi, $$
1381+
$$ \operatorname{atan2}(a,b) = \operatorname{atan2}(-a,-b) + \pi, $$
13821382

13831383
and the second formulation yields values from $0$ continuously to $2\pi$. Thus, we can compute
13841384
$\phi$ as
13851385

1386-
$$ \phi = \text{atan2}(-z, x) + \pi $$
1386+
$$ \phi = \operatorname{atan2}(-z, x) + \pi $$
13871387

13881388
The derivation for $\theta$ is more straightforward:
13891389

1390-
$$ \theta = \text{acos}(-y) $$
1390+
$$ \theta = \arccos(-y) $$
13911391

13921392
<div class='together'>
13931393
So for a sphere, the $(u,v)$ coord computation is accomplished by a utility function that takes
@@ -2491,7 +2491,7 @@
24912491
represents the normal vector. To get this, we just use the cross product of the two side vectors
24922492
$\mathbf{u}$ and $\mathbf{v}$:
24932493

2494-
$$ \mathbf{n} = \text{unit_vector}(\mathbf{u} \times \mathbf{v}) $$
2494+
$$ \mathbf{n} = \operatorname{unit\_vector}(\mathbf{u} \times \mathbf{v}) $$
24952495

24962496
The plane is defined as all points $(x,y,z)$ that satisfy the equation $Ax + By + Cz = D$. Well, we
24972497
know that $\mathbf{Q}$ lies on the plane, so that's enough to solve for $D$:
@@ -3658,7 +3658,7 @@
36583658
As the ray passes through the volume, it may scatter at any point. The denser the volume, the more
36593659
likely that is. The probability that the ray scatters in any small distance $\Delta L$ is:
36603660

3661-
$$ \text{probability} = C \cdot \Delta L $$
3661+
$$ \mathit{probability} = C \cdot \Delta L $$
36623662

36633663
where $C$ is proportional to the optical density of the volume. If you go through all the
36643664
differential equations, for a random number you get a distance where the scattering occurs. If that

0 commit comments

Comments
 (0)