Skip to content

Commit b7dc375

Browse files
committed
quad: another round of review feedback
1 parent b0ec330 commit b7dc375

File tree

1 file changed

+50
-42
lines changed

1 file changed

+50
-42
lines changed

books/RayTracingTheNextWeek.html

Lines changed: 50 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2273,6 +2273,7 @@
22732273

22742274
$$ Ax + By + Cz + D = 0 $$
22752275

2276+
where $A,B,C,D$ are just numbers, and $x,y,z$ are the values of a point $\mathbf{P} = (x,y,z)$.
22762277
That is, a plane is the set of all points $\mathbf{P} = (x,y,z)$ that satisfy the formula above. It
22772278
makes things slightly easier to use the alternate formulation:
22782279

@@ -2315,9 +2316,9 @@
23152316

23162317
We now have three questions we must answer:
23172318

2318-
1. How do we define the quadrilateral in three dimensional space?
2319-
2. How do we find the plane that contains that quadrilateral?
2320-
3. How do we orient the ray-plane intersection point within the quadrilateral?
2319+
1. How do we define the quadrilateral in three dimensional space?
2320+
2. How do we find the plane that contains that quadrilateral?
2321+
3. How do we orient the ray-plane intersection point within the quadrilateral?
23212322

23222323

23232324
Defining the Quadrilateral
@@ -2326,13 +2327,15 @@
23262327
we say "quadrilateral" here, we're really talking about parallelograms, a specific kind of
23272328
quadrilateral where opposite sides are parallel. These three entities are
23282329

2329-
1. $\mathbf{Q}$, the lower-left corner of the quadrilateral.
2330-
2. $\mathbf{u}$, a vector representing the first side of the quadrilateral.
2331-
$\mathbf{Q} + \mathbf{u}$ gives the lower right corner.
2332-
3. $\mathbf{v}$, a vector representing the second side of the quadrilateral.
2333-
$\mathbf{Q} + \mathbf{v}$ gives the upper left corner.
2330+
1. $\mathbf{Q}$, the lower-left corner of the quadrilateral.
2331+
2. $\mathbf{u}$, a vector representing the first side of the quadrilateral.
2332+
$\mathbf{Q} + \mathbf{u}$ gives the lower right corner.
2333+
3. $\mathbf{v}$, a vector representing the second side of the quadrilateral.
2334+
$\mathbf{Q} + \mathbf{v}$ gives the upper left corner.
23342335

2335-
These values are three-dimensional, even though a quad itself is a two-dimensional object.
2336+
These values are three-dimensional, even though a quad itself is a two-dimensional object. For
2337+
example, a quad with corner at the origin and extending two units in the Z direction and one unit in
2338+
the Y direction would have $Q = (0,0,0), u = (0,0,2), \text{and } v = (0,1,0)$.
23362339

23372340
The following figure illustrates the quadrilateral components.
23382341

@@ -2352,7 +2355,11 @@
23522355
The plane is defined as all points $(x,y,z)$ that satisfy the equation $Ax + By + Cz = D$. Well, we
23532356
know that $\mathbf{Q}$ lies on the plane, so we can use that to find $D$:
23542357

2355-
$$ D = \mathbf{n}_x\mathbf{Q}_x + \mathbf{n}_y\mathbf{Q}_y + \mathbf{n}_z\mathbf{Q}_z $$
2358+
$$ \begin{align*}
2359+
D &= \mathbf{n}_x\mathbf{Q}_x + \mathbf{n}_y\mathbf{Q}_y + \mathbf{n}_z\mathbf{Q}_z \\
2360+
&= n \cdot \mathbf{Q} \\
2361+
\end{align*}
2362+
$$
23562363

23572364
We can now use these two values $\mathbf{n}$ and $D$ to find the point of intersection with a given
23582365
ray and the plane containing the quadrilateral.
@@ -2361,8 +2368,9 @@
23612368
Orienting Points on The Plane
23622369
------------------------------
23632370
At this stage, the intersection point is on the plane that contains the quadrilateral, but it could
2364-
be _anywhere_ on the plane, and may lie inside or outside the quadrilateral. We need to determine if
2365-
the intersection lies inside (hits) the quadrilateral, and reject points that lie outside (miss) the
2371+
be _anywhere_ on the plane, and since the quadrilateral may be a small little section of the plane,
2372+
the intersection may lie _inside_ or _outside_ the quadrilateral. We need to determine if the
2373+
intersection lies inside (hits) the quadrilateral, and reject points that lie outside (miss) the
23662374
quad. To determine where a point lies relative to the quad, and to assign texture coordinates to the
23672375
point of intersection, we need to somehow orient the intersection point on the plane.
23682376

@@ -2393,68 +2401,68 @@
23932401
perpendicular, and allowing them to form any angle (other than zero), the math's a little bit
23942402
trickier.
23952403

2396-
$$ \mathbf{P} = \mathbf{Q} + \alpha \mathbf{u} + \beta \mathbf{v}$$
2404+
$$ \mathbf{P} = \mathbf{Q} + \alpha \mathbf{u} + \beta \mathbf{v}$$
23972405

2398-
$$ \mathbf{p} = \mathbf{P} - \mathbf{Q} = \alpha \mathbf{u} + \beta \mathbf{v} $$
2406+
$$ \mathbf{p} = \mathbf{P} - \mathbf{Q} = \alpha \mathbf{u} + \beta \mathbf{v} $$
23992407

24002408
Here, $\mathbf{P}$ is the _point_ of intersection, and $\mathbf{p}$ is the _vector_ from
24012409
$\mathbf{Q}$ to $\mathbf{P}$.
24022410

24032411
Cross the above equation with $\mathbf{u}$ and $\mathbf{v}$, respectively:
24042412

2405-
$$ \begin{align*}
2406-
\mathbf{u} \times \mathbf{p} &= \mathbf{u} \times (\alpha \mathbf{u} + \beta \mathbf{v}) \\
2407-
&= \mathbf{u} \times \alpha \mathbf{u} + \mathbf{u} \times \beta \mathbf{v} \\
2408-
&= \alpha(\mathbf{u} \times \mathbf{u}) + \beta(\mathbf{u} \times \mathbf{v})
2409-
\end{align*} $$
2413+
$$ \begin{align*}
2414+
\mathbf{u} \times \mathbf{p} &= \mathbf{u} \times (\alpha \mathbf{u} + \beta \mathbf{v}) \\
2415+
&= \mathbf{u} \times \alpha \mathbf{u} + \mathbf{u} \times \beta \mathbf{v} \\
2416+
&= \alpha(\mathbf{u} \times \mathbf{u}) + \beta(\mathbf{u} \times \mathbf{v})
2417+
\end{align*} $$
24102418

2411-
$$ \begin{align*}
2412-
\mathbf{v} \times \mathbf{p} &= \mathbf{v} \times (\alpha \mathbf{u} + \beta \mathbf{v}) \\
2413-
&= \mathbf{v} \times \alpha \mathbf{u} + \mathbf{v} \times \beta \mathbf{v} \\
2414-
&= \alpha(\mathbf{v} \times \mathbf{u}) + \beta(\mathbf{v} \times \mathbf{v})
2415-
\end{align*} $$
2419+
$$ \begin{align*}
2420+
\mathbf{v} \times \mathbf{p} &= \mathbf{v} \times (\alpha \mathbf{u} + \beta \mathbf{v}) \\
2421+
&= \mathbf{v} \times \alpha \mathbf{u} + \mathbf{v} \times \beta \mathbf{v} \\
2422+
&= \alpha(\mathbf{v} \times \mathbf{u}) + \beta(\mathbf{v} \times \mathbf{v})
2423+
\end{align*} $$
24162424

24172425
Since any vector crossed with itself yields zero, these equations simplify to
24182426

2419-
$$ \mathbf{u} \times \mathbf{p} = \beta(\mathbf{u} \times \mathbf{v}) $$
2420-
$$ \mathbf{v} \times \mathbf{p} = \alpha(\mathbf{v} \times \mathbf{u}) $$
2427+
$$ \mathbf{u} \times \mathbf{p} = \beta(\mathbf{u} \times \mathbf{v}) $$
2428+
$$ \mathbf{v} \times \mathbf{p} = \alpha(\mathbf{v} \times \mathbf{u}) $$
24212429

24222430
To solve for the coefficients $\alpha$ and $\beta$, we can take the dot product of both sides of the
24232431
above equations with the plane normal $\mathbf{n} = \mathbf{u} \times \mathbf{v}$, reducing both
24242432
sides to scalars.
24252433

2426-
$$ \mathbf{n} \cdot (\mathbf{u} \times \mathbf{p})
2427-
= \mathbf{n} \cdot \beta(\mathbf{u} \times \mathbf{v}) $$
2434+
$$ \mathbf{n} \cdot (\mathbf{u} \times \mathbf{p})
2435+
= \mathbf{n} \cdot \beta(\mathbf{u} \times \mathbf{v}) $$
24282436

2429-
$$ \mathbf{n} \cdot (\mathbf{v} \times \mathbf{p})
2430-
= \mathbf{n} \cdot \alpha(\mathbf{v} \times \mathbf{u}) $$
2437+
$$ \mathbf{n} \cdot (\mathbf{v} \times \mathbf{p})
2438+
= \mathbf{n} \cdot \alpha(\mathbf{v} \times \mathbf{u}) $$
24312439

24322440
Now isolating the coefficients is a simple matter of division:
24332441

2434-
$$ \alpha = \frac{\mathbf{n} \cdot (\mathbf{v} \times \mathbf{p})}
2435-
{\mathbf{n} \cdot (\mathbf{v} \times \mathbf{u})} $$
2442+
$$ \alpha = \frac{\mathbf{n} \cdot (\mathbf{v} \times \mathbf{p})}
2443+
{\mathbf{n} \cdot (\mathbf{v} \times \mathbf{u})} $$
24362444

2437-
$$ \beta = \frac{\mathbf{n} \cdot (\mathbf{u} \times \mathbf{p})}
2438-
{\mathbf{n} \cdot (\mathbf{u} \times \mathbf{v})} $$
2445+
$$ \beta = \frac{\mathbf{n} \cdot (\mathbf{u} \times \mathbf{p})}
2446+
{\mathbf{n} \cdot (\mathbf{u} \times \mathbf{v})} $$
24392447

24402448
Reversing the cross products for both the numerator and denominator of $\alpha$ (recall that
24412449
$\mathbf{a} \times \mathbf{b} = - \mathbf{b} \times \mathbf{a}$) gives us a common denominator for
24422450
both coefficients:
24432451

2444-
$$ \alpha = \frac{\mathbf{n} \cdot (\mathbf{p} \times \mathbf{v})}
2445-
{\mathbf{n} \cdot (\mathbf{u} \times \mathbf{v})} $$
2452+
$$ \alpha = \frac{\mathbf{n} \cdot (\mathbf{p} \times \mathbf{v})}
2453+
{\mathbf{n} \cdot (\mathbf{u} \times \mathbf{v})} $$
24462454

2447-
$$ \beta = \frac{\mathbf{n} \cdot (\mathbf{u} \times \mathbf{p})}
2448-
{\mathbf{n} \cdot (\mathbf{u} \times \mathbf{v})} $$
2455+
$$ \beta = \frac{\mathbf{n} \cdot (\mathbf{u} \times \mathbf{p})}
2456+
{\mathbf{n} \cdot (\mathbf{u} \times \mathbf{v})} $$
24492457

24502458
Now we can perform one final simplification, computing a vector $\mathbf{w}$ that will be constant
24512459
for the plane's basis frame, for any planar point $\mathbf{P}$:
24522460

2453-
$$ \mathbf{w} = \frac{\mathbf{n}}{\mathbf{n} \cdot (\mathbf{u} \times \mathbf{v})}
2454-
= \frac{\mathbf{n}}{\mathbf{n} \cdot \mathbf{n}}$$
2461+
$$ \mathbf{w} = \frac{\mathbf{n}}{\mathbf{n} \cdot (\mathbf{u} \times \mathbf{v})}
2462+
= \frac{\mathbf{n}}{\mathbf{n} \cdot \mathbf{n}}$$
24552463

2456-
$$ \alpha = \mathbf{w} \cdot (\mathbf{p} \times \mathbf{v}) $$
2457-
$$ \beta = \mathbf{w} \cdot (\mathbf{u} \times \mathbf{p}) $$
2464+
$$ \alpha = \mathbf{w} \cdot (\mathbf{p} \times \mathbf{v}) $$
2465+
$$ \beta = \mathbf{w} \cdot (\mathbf{u} \times \mathbf{p}) $$
24582466

24592467

24602468
Implementing Quadrilateral Primitives

0 commit comments

Comments
 (0)