|
2273 | 2273 |
|
2274 | 2274 | $$ Ax + By + Cz + D = 0 $$
|
2275 | 2275 |
|
| 2276 | +where $A,B,C,D$ are just numbers, and $x,y,z$ are the values of a point $\mathbf{P} = (x,y,z)$. |
2276 | 2277 | That is, a plane is the set of all points $\mathbf{P} = (x,y,z)$ that satisfy the formula above. It
|
2277 | 2278 | makes things slightly easier to use the alternate formulation:
|
2278 | 2279 |
|
|
2315 | 2316 |
|
2316 | 2317 | We now have three questions we must answer:
|
2317 | 2318 |
|
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? |
2321 | 2322 |
|
2322 | 2323 |
|
2323 | 2324 | Defining the Quadrilateral
|
|
2326 | 2327 | we say "quadrilateral" here, we're really talking about parallelograms, a specific kind of
|
2327 | 2328 | quadrilateral where opposite sides are parallel. These three entities are
|
2328 | 2329 |
|
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. |
2334 | 2335 |
|
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)$. |
2336 | 2339 |
|
2337 | 2340 | The following figure illustrates the quadrilateral components.
|
2338 | 2341 |
|
|
2352 | 2355 | The plane is defined as all points $(x,y,z)$ that satisfy the equation $Ax + By + Cz = D$. Well, we
|
2353 | 2356 | know that $\mathbf{Q}$ lies on the plane, so we can use that to find $D$:
|
2354 | 2357 |
|
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 | + $$ |
2356 | 2363 |
|
2357 | 2364 | We can now use these two values $\mathbf{n}$ and $D$ to find the point of intersection with a given
|
2358 | 2365 | ray and the plane containing the quadrilateral.
|
|
2361 | 2368 | Orienting Points on The Plane
|
2362 | 2369 | ------------------------------
|
2363 | 2370 | 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 |
2366 | 2374 | quad. To determine where a point lies relative to the quad, and to assign texture coordinates to the
|
2367 | 2375 | point of intersection, we need to somehow orient the intersection point on the plane.
|
2368 | 2376 |
|
|
2393 | 2401 | perpendicular, and allowing them to form any angle (other than zero), the math's a little bit
|
2394 | 2402 | trickier.
|
2395 | 2403 |
|
2396 |
| -$$ \mathbf{P} = \mathbf{Q} + \alpha \mathbf{u} + \beta \mathbf{v}$$ |
| 2404 | + $$ \mathbf{P} = \mathbf{Q} + \alpha \mathbf{u} + \beta \mathbf{v}$$ |
2397 | 2405 |
|
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} $$ |
2399 | 2407 |
|
2400 | 2408 | Here, $\mathbf{P}$ is the _point_ of intersection, and $\mathbf{p}$ is the _vector_ from
|
2401 | 2409 | $\mathbf{Q}$ to $\mathbf{P}$.
|
2402 | 2410 |
|
2403 | 2411 | Cross the above equation with $\mathbf{u}$ and $\mathbf{v}$, respectively:
|
2404 | 2412 |
|
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*} $$ |
2410 | 2418 |
|
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*} $$ |
2416 | 2424 |
|
2417 | 2425 | Since any vector crossed with itself yields zero, these equations simplify to
|
2418 | 2426 |
|
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}) $$ |
2421 | 2429 |
|
2422 | 2430 | To solve for the coefficients $\alpha$ and $\beta$, we can take the dot product of both sides of the
|
2423 | 2431 | above equations with the plane normal $\mathbf{n} = \mathbf{u} \times \mathbf{v}$, reducing both
|
2424 | 2432 | sides to scalars.
|
2425 | 2433 |
|
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}) $$ |
2428 | 2436 |
|
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}) $$ |
2431 | 2439 |
|
2432 | 2440 | Now isolating the coefficients is a simple matter of division:
|
2433 | 2441 |
|
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})} $$ |
2436 | 2444 |
|
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})} $$ |
2439 | 2447 |
|
2440 | 2448 | Reversing the cross products for both the numerator and denominator of $\alpha$ (recall that
|
2441 | 2449 | $\mathbf{a} \times \mathbf{b} = - \mathbf{b} \times \mathbf{a}$) gives us a common denominator for
|
2442 | 2450 | both coefficients:
|
2443 | 2451 |
|
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})} $$ |
2446 | 2454 |
|
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})} $$ |
2449 | 2457 |
|
2450 | 2458 | Now we can perform one final simplification, computing a vector $\mathbf{w}$ that will be constant
|
2451 | 2459 | for the plane's basis frame, for any planar point $\mathbf{P}$:
|
2452 | 2460 |
|
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}}$$ |
2455 | 2463 |
|
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}) $$ |
2458 | 2466 |
|
2459 | 2467 |
|
2460 | 2468 | Implementing Quadrilateral Primitives
|
|
0 commit comments