Last updated: 2026-11-26

13. Rays, spheres and planes

For new readers

Every picture comes down to rays meeting shapes. This page opens the ray itself (an origin, a direction, the point at distance t), the list of hits and which one is visible, and the first two shapes: the sphere and the plane, each as a vector of the conformal algebra, so that "a point lies on it" is a single inner product. The world asks these questions of every object for every ray.

Ray-Sphere Intersections

Rays, spheres, intersection records, the hit rule, and the first picture that comes from casting rays. In the conformal algebra a sphere is a vector, and "a point lies on a sphere" is a single inner product. The book's quadratic comes out of that product instead of being quoted.

Step 0 — a cheaper scalar product (and why it is still the algebra)

Matrices measured about 0.36 ms for one mat_tuple, and flagged it: each row-times-column dot product computed a full 32×32 geometric product only to keep its scalar part. A per-pixel renderer cannot afford that.

The scalar part of ab needs only the products of each blade with itself (any other pair lands in a different grade), so ⟨ab⟩₀ = Σₖ aₖ bₖ sign(k,k): 32 terms instead of 1024. It is a standard GA operation, not a shortcut around one; the first test of this step requires it to equal ⟨ab⟩₀ of the full product on dense mixed multivectors (exact, six pairs).the dot product is just a weighted sum of components

# Scalar part of the geometric product, <a b>_0. Only products of a blade
# with itself reach grade 0, so this needs the 32 same-blade terms, not the
# 1024 pairs of the full product: sum_k a_k b_k sign(k,k).
make a function called ga_scalar_prod takes a, b returns s
  let s = 0
  let k = 0
  while k < 32 do
    let ak = a[k]
    if ak != 0 then
      let s = s + ak * b[k] * ga_square_sign(k)
    end
    let k = k + 1
  end
  return s
end

The homogeneous weight −(e∞ · t) also reads through it, and e∞, e0 became literal constants instead of being rebuilt on every call. Measured on 2 000 calls (the Matrices benchmark, same machine):

operation Matrices scalar product + literal e∞, e0
mat_tuple 721 ms 394 ms 237 ms
mat_mul 1 672 ms 393 ms 384 ms

All the earlier pages' suites pass unchanged:

Step 1 — rays

A ray is an origin (a conformal point) and a direction (a bivector d ∧ e∞). The point at distance t is the origin translated by t times the direction — the same translator sandwich as in Points, directions and motions in the conformal algebra.

make a function called ray takes origin, direction returns r
  return [origin, direction]
end

make a function called ray_origin takes r returns o
  return r[0]
end

make a function called ray_direction takes r returns d
  return r[1]
end

make a function called position takes r, t returns p
  return tuple_add(r[0], tuple_mul(r[1], t))
end

make a function called transform_ray takes r, m returns r2
  return ray(mat_tuple(m, r[0]), mat_tuple(m, r[1]))
end

Step 2 — the sphere is a vector, the quadratic is an inner product

The unit sphere at the origin is the conformal vector S₀ = e0 − ½ e∞. A conformal point X lies on it exactly when X · S₀ = 0. A point on a ray is

X(t) = O + t d + ( t (o·d) + ½ t² d² ) e∞        (o, d: the Euclidean parts)

and with e0 · e∞ = −1, X(t) · S₀ = 0 expands to

d² t² + 2 (o·d) t + (−2 O·S₀) = 0       with  −2 O·S₀ = |o|² − 1

which is the book's a, b, c — each one an inner product, c being the conformal inner product of the ray's origin with the sphere.

A sphere carries its transformation and the inverse of it (Light at a point, and shadows adds a material and a normal matrix to the same record), computed once in set_transform, so intersect does not re-invert on every ray (the book's pseudocode inverts per call). intersect moves the ray into the sphere's object space with that inverse, as this page describes, and intersects with S₀.

make a function called new_shape takes kind returns s
  let id = identity_matrix()
  # params: [minimum, maximum, closed] for cylinders and cones (chapter 13); [] for the rest
  let params = []
  if kind == "cylinder" or kind == "cone" then
    let params = [0 - infinity(), infinity(), false]
  end
  if kind == "group" then
    let params = [[], false]
  end
  # the abstract test shape records the last ray it was given (in object space) here
  if kind == "test" then
    let params = [new("SavedRay")]
  end
  return [new("ShapeId"), id, id, material(), normal_matrix(id), kind, params, false, true, false]
end

make a function called sphere returns s
  return new_shape("sphere")
end

make a function called plane returns s
  return new_shape("plane")
end

# an abstract shape for testing the common behaviour: it records the local
# ray it is given (test_shape_saved_ray) and its local normal is its point as a vector
make a function called test_shape returns s
  return new_shape("test")
end

make a function called shape_transform takes s returns m
  return s[1]
end

make a function called shape_inverse takes s returns m
  return s[2]
end

make a function called shape_material takes s returns m
  return s[3]
end

make a function called shape_kind takes s returns k
  return s[5]
end

# set_transform / set_material return a new shape (values are not mutated in place)
make a function called set_transform takes s, m returns s2
  return [s[0], m, inverse(m), s[3], normal_matrix(m), s[5], s[6], s[7], m == identity_matrix(), s[9]]
end

make a function called set_material takes s, m returns s2
  return [s[0], s[1], s[2], m, s[4], s[5], s[6], s[7], s[8], s[9]]
end
# the unit sphere at the origin as a conformal vector: e0 - einf/2, which in the
# orthonormal basis is simply -e+ (the test tree, shapes/pieces/conformal, checks the sphere vector)
make a function called unit_sphere_vector returns s
  return [0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
end

# the xz-plane as a conformal vector: pi = e2
make a function called plane_vector returns p
  return [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
end

# The sphere's quadratic from the ray's components. In the conformal algebra the three
# coefficients are inner products: d.d, 2 o.d, and -2 (o . S) for the sphere vector S,
# which for a point o is |o|^2 - 1 and is read straight from o's e+ coefficient
# (o[8] = (|o|^2 - 1) / 2). Written on components because this runs for every ray and every
# shadow ray (the test tree, shapes/sphere/ways, checks it against the multivector form).
make a function called sphere_local_intersect takes s, r returns xs
  let o = r[0]
  let d = r[1]
  let dx = get_x(d)
  let dy = get_y(d)
  let dz = get_z(d)
  let a = dx * dx + dy * dy + dz * dz
  let b = 2 * (get_x(o) * dx + get_y(o) * dy + get_z(o) * dz)
  let c = 2 * o[8]
  let disc = b * b - 4 * a * c
  if disc < 0 then
    return []
  end
  let root = sqrt(disc)
  return [intersection((0 - b - root) / (2 * a), s), intersection((0 - b + root) / (2 * a), s)]
end
# the normal at a point of the shape, in object space
make a function called local_normal_at_hit takes s, p, hit returns n
  let kind = s[5]
  if kind == "sphere" then
    return tuple_sub(p, point(0, 0, 0))
  end
  if kind == "plane" then
    let pv = plane_vector()
    return vector(pv[1], pv[2], pv[4])
  end
  if kind == "cube" then
    return cube_local_normal_at(p)
  end
  if kind == "cylinder" then
    return cylinder_local_normal(s, p)
  end
  if kind == "cone" then
    return cone_local_normal(s, p)
  end
  if kind == "triangle" then
    return s[6][5]
  end
  if kind == "torus" then
    return torus_local_normal(s, p)
  end
  if kind == "implicit" then
    return implicit_local_normal(s, p)
  end
  if kind == "function" then
    return function_local_normal(s, p)
  end
  if kind == "smooth_triangle" then
    return smooth_triangle_normal(s, hit)
  end
  if kind == "group" or kind == "csg" then
    return false
  end
  return vector(get_x(p), get_y(p), get_z(p))
end

Step 3 — intersection records, sorting, the hit

An intersection is [t, object]. intersections returns its input sorted by t; it is a merge sort, so it stays O(n log n) when later pages collect many intersections per ray. hit is the lowest non-negative t, or the empty list ("nothing") when every t is negative.

make a function called intersection takes t, object returns i
  return [t, object]
end

make a function called i_t takes i returns t
  return i[0]
end

make a function called i_object takes i returns o
  return i[1]
end

make a function called merge_by_t takes a, b returns merged
  let out = []
  let i = 0
  let j = 0
  while i < a.length and j < b.length do
    if a[i][0] <= b[j][0] then
      let out = list_push(out, a[i])
      let i = i + 1
    else
      let out = list_push(out, b[j])
      let j = j + 1
    end
  end
  while i < a.length do
    let out = list_push(out, a[i])
    let i = i + 1
  end
  while j < b.length do
    let out = list_push(out, b[j])
    let j = j + 1
  end
  return out
end

# the given intersection records, sorted by increasing t (merge sort)
make a function called intersections takes xs returns sorted
  if xs.length <= 1 then
    return xs
  end
  let mid = floor(xs.length / 2)
  let left = []
  let right = []
  let i = 0
  while i < xs.length do
    if i < mid then
      let left = list_push(left, xs[i])
    else
      let right = list_push(right, xs[i])
    end
    let i = i + 1
  end
  return merge_by_t(intersections(left), intersections(right))
end
# the visible intersection: lowest non-negative t, or [] if there is none
make a function called hit takes xs returns i
  let best = []
  let k = 0
  while k < xs.length do
    if xs[k][0] >= 0 then
      if best.length == 0 then
        let best = xs[k]
      elif xs[k][0] < best[0] then
        let best = xs[k]
      end
    end
    let k = k + 1
  end
  return best
end

Step 4 — checks

Rays through, past, inside and behind a sphere are worked by hand; a moved sphere is hit where it now is; the shape receives the ray in its own space. Then every sphere, plain and turned, stretched and moved, is checked against x² + y² + z² = 1: every hit lies on it, no crossing found by marching along a ray is missed, and the normal lies along the gradient. The tangent case needs no special handling: with exact rational arithmetic the discriminant is exactly 0, sqrt(0) is exactly 0, and both t values are equal.

Further checks, sharing no code with what they check:

  • the usual quadratic on plain coordinates, written without any algebra, agrees with intersect on ten rays (hits and misses);
  • every returned point satisfies X · S₀ = 0 exactly — the points are on the sphere as a conformal fact, not just at the right distance — with a negative control (an off-sphere point has X · S₀ ≠ 0);
  • geometry: rotating a unit sphere changes nothing (t = 4, 6), scaling by 2 in y gives an ellipsoid that a y-ray enters at y = −2 but a z-ray still meets at z = −1, and a sphere moved to (0,3,0) is hit by a ray at y = 3;
  • sorting of twelve shuffled values.

Step 5 — Putting it together: the silhouette

One ray per pixel from (0, 0, −5) through a 7-unit wall at z = 10; every hit is painted red.

# Chapter 5, "Putting It Together": cast one ray per pixel at a unit sphere
# and paint the hits red. The wall is 7 units square at z = 10, the ray
# origin at z = -5.
include "../lib/spec.patlang"
include "../lib/png.patlang"
include "../lib/ray.patlang"
include "../lib/shape.patlang"

make a function called render_silhouette takes canvas_pixels returns c
  let ray_origin_pt = point(0, 0, -5)
  let wall_z = 10
  let wall_size = 7
  let pixel_size = wall_size / canvas_pixels
  let half = wall_size / 2
  let c = canvas(canvas_pixels, canvas_pixels)
  let red_c = color(1, 0, 0)
  let shape = sphere()
  let y = 0
  while y < canvas_pixels do
    let world_y = half - pixel_size * y
    let x = 0
    while x < canvas_pixels do
      let world_x = 0 - half + pixel_size * x
      let target = point(world_x, world_y, wall_z)
      let r = ray(ray_origin_pt, normalize(tuple_sub(target, ray_origin_pt)))
      let xs = intersect(shape, r)
      if hit(xs).length > 0 then
        write_pixel(c, x, y, red_c)
      end
      let x = x + 1
    end
    let y = y + 1
  end
  return c
end

let t0 = now_ms()
let c = render_silhouette(400)
print("rendered 400x400 in " + (now_ms() - t0) + " ms")
save_png(c, "../out/ch05_silhouette.png")
print("wrote out/ch05_silhouette.png")
> cd examples && v2_interp.exe ch05_silhouette.patlang
rendered 400x400 in 162865 ms
wrote out/ch05_silhouette.png

Sphere silhouette

Checking it independently

A pixel at wall position (wx, wy) is a hit exactly when the line from (0, 0, −5) to (wx, wy, 10) passes within 1 of the origin. The distance from a point to a line gives wx² + wy² ≤ 225/24, with no algebra library and none of this project's code. .NET decodes the PNG and every one of the 160 000 pixels is compared with that formula:

> powershell.exe -NoProfile -File tools/verify_silhouette.ps1 out/ch05_silhouette.png
decoded by .NET: 400x400; red pixels: 96173; pixels that are neither red nor black: 0; pixels disagreeing with the closed form: 0

Cost

Render time against canvas size (side doubles, so pixels quadruple):

canvas time per pixel
25 × 25 321 ms 0.51 ms
50 × 50 1 305 ms 0.52 ms
100 × 100 5 308 ms 0.53 ms

Linear in pixels, about half a millisecond each. That is fine for a silhouette and is the budget the pages that follow have to spend on shading, shadows and reflections; profiling will come when something exceeds it.

Planes

Two jobs: refactor the sphere into a general shape, then add a plane. The refactor pulls everything shapes have in common into one place; the plane then needs only its own intersection and its own normal. In the conformal algebra the plane turns out to be the same kind of object as the sphere — a vector — and its intersection formula is the sphere's condition X · S = 0, specialised.

Step 1 — the shape

A shape is [id, transform, inverse, material, normal_matrix, kind]. The common behaviour is exactly the book's four items:

  • a transformation (default identity) and a material (default Phong);
  • intersect(shape, ray) transforms the ray by the inverse of the shape's transformation, then calls the shape's own local_intersect;
  • normal_at(shape, point) moves the point into object space, calls the shape's local_normal_at, and carries the result back.

The last step is where Light at a point, and shadows's choice pays off. The cofactor matrix that transforms the normal does not depend on the shape, so it lives here, once, instead of being repeated in each shape. All sphere code moved from ray.patlang into the new shape.patlang; ray.patlang keeps rays, intersection records, sorting and hit.

make a function called new_shape takes kind returns s
  let id = identity_matrix()
  # params: [minimum, maximum, closed] for cylinders and cones (chapter 13); [] for the rest
  let params = []
  if kind == "cylinder" or kind == "cone" then
    let params = [0 - infinity(), infinity(), false]
  end
  if kind == "group" then
    let params = [[], false]
  end
  # the abstract test shape records the last ray it was given (in object space) here
  if kind == "test" then
    let params = [new("SavedRay")]
  end
  return [new("ShapeId"), id, id, material(), normal_matrix(id), kind, params, false, true, false]
end

make a function called sphere returns s
  return new_shape("sphere")
end

make a function called plane returns s
  return new_shape("plane")
end

# an abstract shape for testing the common behaviour: it records the local
# ray it is given (test_shape_saved_ray) and its local normal is its point as a vector
make a function called test_shape returns s
  return new_shape("test")
end

make a function called shape_transform takes s returns m
  return s[1]
end

make a function called shape_inverse takes s returns m
  return s[2]
end

make a function called shape_material takes s returns m
  return s[3]
end

make a function called shape_kind takes s returns k
  return s[5]
end

# set_transform / set_material return a new shape (values are not mutated in place)
make a function called set_transform takes s, m returns s2
  return [s[0], m, inverse(m), s[3], normal_matrix(m), s[5], s[6], s[7], m == identity_matrix(), s[9]]
end

make a function called set_material takes s, m returns s2
  return [s[0], s[1], s[2], m, s[4], s[5], s[6], s[7], s[8], s[9]]
end
make a function called local_intersect takes s, r returns xs
  let kind = s[5]
  # the commonest kinds first: the chain is a string comparison per step
  if kind == "sphere" then
    return sphere_local_intersect(s, r)
  end
  if kind == "plane" then
    return plane_local_intersect(s, r)
  end
  if kind == "triangle" or kind == "smooth_triangle" then
    return triangle_local_intersect(s, r)
  end
  if kind == "group" then
    return group_local_intersect(s, r)
  end
  if kind == "cube" then
    return cube_local_intersect(s, r)
  end
  if kind == "csg" then
    return csg_local_intersect(s, r)
  end
  if kind == "cylinder" then
    return cylinder_local_intersect(s, r)
  end
  if kind == "cone" then
    return cone_local_intersect(s, r)
  end
  if kind == "torus" then
    return torus_local_intersect(s, r)
  end
  if kind == "implicit" then
    return implicit_local_intersect(s, r)
  end
  if kind == "function" then
    return function_local_intersect(s, r)
  end
  if kind == "test" then
    let saved = s[6][0]
    saved.ray = r
  end
  return []
end

make a function called intersect takes s, r returns xs
  if s[8] then
    return local_intersect(s, r)
  end
  return local_intersect(s, transform_ray(r, s[2]))
end

make a function called local_normal_at takes s, p returns n
  return local_normal_at_hit(s, p, false)
end

test_shape is the book's abstract shape. A shape is a value (a list), so it cannot change itself to "save" the ray it was given; it holds a small object made for it alone (a SavedRay, which every copy of the shape shares), its local_intersect stores the ray there, and the tests read it back with test_shape_saved_ray(s).

Step 2 — the plane is a vector

A conformal point X lies on a plane exactly when X · π = 0, where π = n + d e∞ is the plane as a vector (unit normal n, offset d from the origin). It is the sphere's condition with a different vector. The book's plane is the xz-plane, so π = e2.the plane is a sphere of infinite radius

Put a ray point X(t) = O + t d + (…) e∞ into it. The e∞ term is orthogonal to e2, so only the Euclidean parts remain:

X(t) · e2 = o_y + t d_y = 0      ⟹      t = −(O · π) / (d · π)

That is the book's t = −origin_y / direction_y, and it is written with two inner products, so the same code gives t for the plane vector of any plane. The normal is the Euclidean part of π, constant everywhere. A ray with |d · π| < EPSILON is parallel to the plane and misses it; a coplanar ray is treated as a miss, as the book says.

# the xz-plane as a conformal vector: pi = e2
make a function called plane_vector returns p
  return [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
end

# The sphere's quadratic from the ray's components. In the conformal algebra the three
# coefficients are inner products: d.d, 2 o.d, and -2 (o . S) for the sphere vector S,
# which for a point o is |o|^2 - 1 and is read straight from o's e+ coefficient
# (o[8] = (|o|^2 - 1) / 2). Written on components because this runs for every ray and every
# shadow ray (the test tree, shapes/sphere/ways, checks it against the multivector form).
make a function called sphere_local_intersect takes s, r returns xs
  let o = r[0]
  let d = r[1]
  let dx = get_x(d)
  let dy = get_y(d)
  let dz = get_z(d)
  let a = dx * dx + dy * dy + dz * dz
  let b = 2 * (get_x(o) * dx + get_y(o) * dy + get_z(o) * dz)
  let c = 2 * o[8]
  let disc = b * b - 4 * a * c
  if disc < 0 then
    return []
  end
  let root = sqrt(disc)
  return [intersection((0 - b - root) / (2 * a), s), intersection((0 - b + root) / (2 * a), s)]
end

# A ray parallel to the plane (d . pi ~ 0) never meets it; a coplanar ray is
# treated as a miss, as the book does.
make a function called plane_local_intersect takes s, r returns xs
  let dy = get_y(r[1])
  if abs(dy) < epsilon() then
    return []
  end
  return [intersection(0 - r[0][2] / dy, s)]
end

make a function called local_intersect takes s, r returns xs
  let kind = s[5]
  # the commonest kinds first: the chain is a string comparison per step
  if kind == "sphere" then
    return sphere_local_intersect(s, r)
  end
  if kind == "plane" then
    return plane_local_intersect(s, r)
  end
  if kind == "triangle" or kind == "smooth_triangle" then
    return triangle_local_intersect(s, r)
  end
  if kind == "group" then
    return group_local_intersect(s, r)
  end
  if kind == "cube" then
    return cube_local_intersect(s, r)
  end
  if kind == "csg" then
    return csg_local_intersect(s, r)
  end
  if kind == "cylinder" then
    return cylinder_local_intersect(s, r)
  end
  if kind == "cone" then
    return cone_local_intersect(s, r)
  end
  if kind == "torus" then
    return torus_local_intersect(s, r)
  end
  if kind == "implicit" then
    return implicit_local_intersect(s, r)
  end
  if kind == "function" then
    return function_local_intersect(s, r)
  end
  if kind == "test" then
    let saved = s[6][0]
    saved.ray = r
  end
  return []
end

make a function called local_normal_at takes s, p returns n
  return local_normal_at_hit(s, p, false)
end

Step 3 — checks

The plane is checked like every shape, against its function (here y), plain and turned and moved; hits, and the rays that cannot hit (parallel above it, lying in it), are worked by hand; the normal is the same everywhere; and the algebra's form of the intersection agrees with the coordinate form on a fan of rays.

Further checks, sharing no code with what they check:

  • t = −(O · π)/(d · π) agrees with −origin_y/direction_y on five rays, including a parallel one, and every hit point satisfies X · π = 0 (with a negative control: a point above the plane does not);
  • transformed planes: for five transformations (a wall at z = 5, rotations and translations in combination, a non-uniform scale) every hit point lies in the world plane through the image of the origin with the world normal n from normal_at — n · (X − p₀) = 0 — over 23 hits.

Step 4 — Putting it together: spheres on a plane

The three balls of the camera page on a single plane for the floor, then the same scene with a second plane as a backdrop (rotated π/2 about x and moved back to z = 6).

# Chapter 9, "Putting It Together": the three spheres on a plane floor, and a
# second view with a plane backdrop (rotated pi/2 about x and moved back).
include "../lib/spec.patlang"
include "../lib/png.patlang"
include "../lib/camera.patlang"
include "../lib/demo_scene.patlang"

let w = build_plane_scene()
let cam = set_camera_transform(camera(400, 200, pi() / 3), view_transform(spheres_view()[0], spheres_view()[1], vector(0, 1, 0)))
render_example(cam, w, "../out/ch09_plane_floor.png")

let backdrop = set_material(set_transform(plane(), mat_mul(translation(0, 0, 6), rotation_x(pi() / 2))), material_with(color((2/5), (3/5), 1), (1/10), (9/10), 0, 200))
let w2 = set_world_objects(w, list_push(world_objects(w), backdrop))
render_example(cam, w2, "../out/ch09_plane_backdrop.png")
> tools/prender.sh examples/ch09_plane_floor.patlang
assembled 400x200 from 40 bands
assembled 400x200 from 40 bands
rendered with 9 parallel processes (40 bands) in 520 s wall clock
Spheres on a plane Spheres on a plane with a backdrop

Checking it independently

The from-scratch tracer learned planes (t = −o_y/d_y in object space, local normal (0, 1, 0), then the book's transpose(inverse(M))) and a scene selector. Every pixel of both 400×200 images (80 000 each), with shadows:

> powershell.exe -NoProfile -File tools/verify_scene.ps1 out/ch09_plane_floor.png -Scene plane -Shadows -Stride 1
decoded by .NET: 400x200; pixels covered by an object: 63645; pixels differing from the independent tracer by more than 1 level: 0 (max difference 0); stride 1 in each direction, 80000 pixels checked
> powershell.exe -NoProfile -File tools/verify_scene.ps1 out/ch09_plane_backdrop.png -Scene backdrop -Shadows -Stride 1
decoded by .NET: 400x200; pixels covered by an object: 80000; pixels differing from the independent tracer by more than 1 level: 0 (max difference 0); stride 1 in each direction, 80000 pixels checked

The images of the camera page and of light and shadow are still checked by the same script against their own scenes (their docs run it).

Cost

A floor-only render costs about 1.3 ms per pixel with shadows, against 2.2 ms for the Light at a point, and shadows sphere-floor scene (both measured alone at 200×100): a plane is one division, not a quadratic, and the floor is no longer a flattened sphere that needs a full transform-and-solve.

How it is checked

> v2_interp.exe tests/run.patlang --node shapes/rays --depth 2
[ ok ] Rays and lists of hits
[ ok ]   A ray keeps its origin and direction; t walks along it
[ ok ]   A transformed ray: the origin moves and stretches, the direction only stretches
[ ok ]   A hit records its t and its object
[ ok ]   The visible hit is the nearest one in front
[ ok ]   Sorting hits by t
[ ok ]     intersections() sorts and keeps every hit
[ ok ]     Merging two sorted lists equals sorting both together
checks: 6 passed, 0 failed, 0 blocked, 0 skipped, 0 not run
ALL PASSED
> v2_interp.exe tests/run.patlang --node shapes/sphere --depth 2
[ ok ] Spheres
[ ok ]   Rays through, past, inside and behind a unit sphere
[ ok ]   A moved sphere is hit where it now is
[ ok ]   intersect hands the shape the ray in the shape's own space
[ ok ]   Normals of a sphere, a moved one and a squashed one
[ ok ]   A glass sphere is clear with index 1.5
[ ok ]   Against x^2 + y^2 + z^2 = 1
[ ok ]     Every hit lies on the surface
[ ok ]     No crossing of the surface is missed
[ ok ]     Normals follow the gradient of the surface's function
[ ok ]   Turned, stretched and moved
[ ok ]     Every hit lies on the surface
[ ok ]     No crossing of the surface is missed
[ ok ]     Normals follow the gradient of the surface's function
[ ok ]   Two ways to meet a sphere  (all, giving the same answer)
[ ok ]     naive: every coefficient an inner product of the algebra
[ ok ]     faster: the same quadratic on the coordinates
[ ok ]   Further checks, independent of the code they check
[ ok ]     Intersect agrees with the book's formula on 10 rays (hits and misses)
[ ok ]     The unit sphere vector = e0 - einf/2 (= -e+)
[ ok ]     Every returned point has X . S = 0 exactly
[ ok ]     A rotated unit sphere is the same sphere: t = 4
[ ok ]     Intersections() returns a sorted list (12 shuffled values)
checks: 18 passed, 0 failed, 0 blocked, 0 skipped, 0 not run
ALL PASSED
> v2_interp.exe tests/run.patlang --node shapes/plane --depth 2
[ ok ] Planes
[ ok ]   Hitting the floor, and the rays that cannot
[ ok ]   The normal is straight up everywhere
[ ok ]   Against y = 0
[ ok ]     Every hit lies on the surface
[ ok ]     No crossing of the surface is missed
[ ok ]     Normals follow the gradient of the surface's function
[ ok ]   Turned and moved
[ ok ]     Every hit lies on the surface
[ ok ]     No crossing of the surface is missed
[ ok ]     Normals follow the gradient of the surface's function
[ ok ]   Two ways to meet a plane  (all, giving the same answer)
[ ok ]     naive: -(O . pi) / (d . pi) with the plane's vector
[ ok ]     faster: the y coordinates
[ ok ]   Further checks, independent of the code they check
[ ok ]     T = -(O.pi)/(d.pi) agrees with -origin.y/direction.y (5 rays, incl. parallel)
[ ok ]     Hits on 5 transformed planes satisfy n . (X - p0) = 0
checks: 12 passed, 0 failed, 0 blocked, 0 skipped, 0 not run
ALL PASSED