Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Vectors and Geometry  ›  Lesson

Rays, Planes and Normals

Geometry 15 minA ray is a start point plus a scaled direction, a plane is every point whose dot product with a unit normal equals an offset, and two dot products give a point's signed distance and a ray's hit.

Rays, Planes and Normals

While the player holds the drop button, Harbour Hopper shows a small target ring where the crate will land: on a deck, on the sloping boat ramp, or in the water. To place it, the game fires an invisible ray straight down from the drone and asks where it first meets a surface. Two dot products and one division answer that.

The rule

Signed distance to a plane: normal dot point, minus offset.

A ray is a start point plus a direction that can be stretched: p(t)=o+t u\mathbf{p}(t) = \mathbf{o} + t\,\mathbf{u} with t≥0t \ge 0. When u\mathbf{u} is a unit vector, tt is simply the distance travelled.

A plane — in our side view a line, in 3D a flat sheet — is described by a unit normal n\mathbf{n}, the arrow sticking straight out of the surface, and an offset dd. The plane is every point p\mathbf{p} with n⋅p=d\mathbf{n} \cdot \mathbf{p} = d. The water is n=(0,1), d=0\mathbf{n} = (0, 1),\ d = 0; the deck is n=(0,1), d=2\mathbf{n} = (0, 1),\ d = 2.

The signed distance of any point from the plane is s=n⋅p−ds = \mathbf{n} \cdot \mathbf{p} - d. It is positive on the side the normal points to, zero on the plane and negative behind it. A crate at (7,−0.4)(7, -0.4) has s=−0.4s = -0.4 against the water: it is 0.4 m under.

To hit a plane with a ray, put p(t)\mathbf{p}(t) into the plane's rule and solve for tt:

t=d−n⋅on⋅ut = \dfrac{d - \mathbf{n} \cdot \mathbf{o}}{\mathbf{n} \cdot \mathbf{u}}

If n⋅u=0\mathbf{n} \cdot \mathbf{u} = 0, the ray runs parallel to the plane and never crosses it. If t<0t < 0, the plane is behind the ray's start.

The shortcut

Two dots and a divide. Compute n⋅o\mathbf{n} \cdot \mathbf{o} and n⋅u\mathbf{n} \cdot \mathbf{u}; then tt = (offset − first dot) ÷ second dot. The first dot hands you the signed distance for free.

The boat ramp slopes down into the water along 0.6x+0.8y=60.6x + 0.8y = 6, so n=(0.6,0.8)\mathbf{n} = (0.6, 0.8) and d=6d = 6. The drone is at (4,9)(4, 9) and the ray points straight down, u=(0,−1)\mathbf{u} = (0, -1).

Where does the target ring land on the ramp?Step 1 of 5
  1. Normal dot start

    0.6 × 4 + 0.8 × 9 = 2.4 + 7.2 = 9.6.

Notice that 4.5 m straight down is more than the 3.6 m signed distance: on a slope, "straight down" is not the shortest way to the surface.

The trap is a normal that isn't unit length. Use (3,4)(3, 4) with d=30d = 30 instead of (0.6,0.8)(0.6, 0.8) with d=6d = 6 and it's the same ramp, but every signed distance comes out five times too big.

Drills

Answer fast — trust the rule.

quick drill

The water is n = (0, 1), d = 0. A crate sits at (7, −0.4). What does its signed distance say?

The deck is n = (0, 1), d = 2. The drone at (3, 10) fires a ray straight down, u = (0, −1). At what t does it hit?
(2−10)÷(−1)= ?(2 - 10) \div (-1) = \,?
quick drill

A ray gives n · u = 0. What does that mean?

quick drill

A ray–plane test returns t = −3. What should the target ring do?

quick drill

For the ramp 0.6x + 0.8y = 6, where is a gull at (10, 3)?

Remember

  • A ray is o + t·u; a plane is every point with n · p = d, using a unit normal.
  • Signed distance = n · p − d: positive in front, zero on, negative behind.
  • Ray hit: t = (d − n · o) ÷ (n · u); a zero divisor means parallel, and a negative t means behind.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainLanding ring on the ramp

Explain how Harbour Hopper places the landing ring under the drone at (4, 9) on the ramp 0.6x + 0.8y = 6, and what the game should do if the drone has flown below the ramp's surface.