Last updated: 2026-11-26

14. Boxes, cylinders and cones

For new readers

More shapes for the world to ask about: the cube (six planes), and the cylinder and cone (quadrics about the y axis), each with its own limits and lids. The built objects of part III are made largely of these.

Cubes

The axis-aligned cube from −1 to 1 on every axis, with two jobs: intersect a ray with it, and find its normal. In the conformal algebra both are statements about plane vectors, and the cube is six of them.

Step 1 — a cube is six plane vectors

A plane is the vector π = n + d e∞ (unit normal n, offset d), and a point P lies on it when P · π = p·n − d = 0. The faces of the cube are

π = ±e1 + e∞,   π = ±e2 + e∞,   π = ±e3 + e∞        (offset 1, normals ±eᵢ)

and a ray meets each face where t = −(O · π) / (d · π) — the same expression as the plane of Rays, spheres and planes. The two faces of one axis are parallel, so each axis gives an interval [t_near, t_far]. The ray is inside the cube between the largest near value and the smallest far value, and misses when they cross. That is the book's check_axis: its numerators (−1 − origin) and (1 − origin) are −(O · π) for the two faces.

The normal is the unit normal of the face plane nearest the point, the smallest |P · π|. For a point on the surface that is the face it lies on, which is the book's "largest absolute coordinate", and ties at an edge or corner go to the first face in the order +x, −x, +y, −y, +z, −z, as the book's table requires.

# face plane vector for axis (0,1,2) and sign (+1 / -1): sign * e_axis + einf
make a function called cube_face_vector takes axis, sign returns pi
  let v = cga_einf()
  return list_set(v, 1 shl axis, sign)
end

# [t_near, t_far] along one axis; [] if the ray misses the slab; false if the
# ray is parallel to the axis' faces and strictly between them (no constraint;
# a ray lying IN a face plane is a miss, as a coplanar ray is for a plane)
make a function called cube_axis_range takes o, dvec, axis returns range
  let pp = cube_face_vector(axis, 1)
  let pm = cube_face_vector(axis, -1)
  let dp = ga_vec_dot(dvec, pp)
  if abs(dp) < epsilon() then
    if abs(ga_vec_dot(o, pp) + 1) < 1 then
      return false
    end
    return []
  end
  let a = 0 - ga_vec_dot(o, pp) / dp
  let b = 0 - ga_vec_dot(o, pm) / ga_vec_dot(dvec, pm)
  if a > b then
    return [b, a]
  end
  return [a, b]
end

make a function called cube_local_intersect takes s, r returns xs
  # the slab test of the six plane vectors, written on the ray's components (see cube_axis_range
  # for the plane-vector form: t = -(O . pi) / (d . pi) is (+-1 - o_axis) / d_axis for the
  # faces at +-1). A ray parallel to an axis must lie strictly between its faces.
  let o = r[0]
  let d = r[1]
  let tmin = 0 - infinity()
  let tmax = infinity()
  let axis = 0
  while axis < 3 do
    let bit = 1
    if axis == 1 then
      let bit = 2
    elif axis == 2 then
      let bit = 4
    end
    let oa = o[bit]
    let da = d[8 + bit]
    if abs(da) < epsilon() then
      if abs(oa) >= 1 then
        return []
      end
    else
      let t1 = (-1 - oa) / da
      let t2 = (1 - oa) / da
      if t1 > t2 then
        let tmp = t1
        let t1 = t2
        let t2 = tmp
      end
      if t1 > tmin then
        let tmin = t1
      end
      if t2 < tmax then
        let tmax = t2
      end
    end
    let axis = axis + 1
  end
  if tmin > tmax then
    return []
  end
  return [intersection(tmin, s), intersection(tmax, s)]
end

make a function called cube_local_normal_at takes p returns n
  let best = 0
  let best_d = 0
  let k = 0
  while k < 6 do
    let axis = floor(k / 2)
    let sign = 1
    if k % 2 == 1 then
      let sign = -1
    end
    let d = abs(ga_vec_dot(p, cube_face_vector(axis, sign)))
    if k == 0 or d < best_d then
      let best = k
      let best_d = d
    end
    let k = k + 1
  end
  let sign = 1
  if best % 2 == 1 then
    let sign = -1
  end
  let axis = floor(best / 2)
  if axis == 0 then
    return cga_direction(sign, 0, 0)
  end
  if axis == 1 then
    return cga_direction(0, sign, 0)
  end
  return cga_direction(0, 0, sign)
end

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

Step 2 — a boundary the book leaves open

When a ray is parallel to a pair of faces the book multiplies the numerators by infinity, to keep their signs. If the ray lies in a face plane one numerator is zero and the product is 0 × ∞: NaN in IEEE arithmetic, and undefined in the pseudocode. In practice the book's answer then depends on the ray's direction — a ray along a face plane travelling toward the cube comes out as a miss, and the same ray travelling away comes out as a hit with negative t.

Here a parallel ray must lie strictly between the two faces, otherwise it misses; a ray in a face plane is a miss whichever way it points. That is the same convention the book uses for a ray coplanar with a plane in Rays, spheres and planes, and it is tested directly (a ray in the plane z = 1: miss; at z = 0.999: hit with t = 2, 4; at z = 1.001: miss). The comparison with the book's formula (below) sets aside exactly the rays that lie in a face plane, and says how many.coplanar rays are misses here, as with spheres

Step 3 — checks

Rays through faces, from inside and past a corner, and the normals of three faces, are worked by hand; plain and turned, stretched and moved, the cube is checked against max(|x|, |y|, |z|) = 1 like every shape.

Further checks, sharing no code with what they check:

  • The six-plane-vector slab test against the book's check_axis, written out on plain coordinates, on a grid of 39 088 rays whose origins and directions are exact fractions, so exact grazes (a ray passing precisely through an edge, t_near = t_far) are compared exactly. This grid is built from rationals deliberately: with decimal floats the same comparison reported mismatches at those exact grazes, because the conformal inner product P · π subtracts two nearly equal coefficients, (a − ½) − (a + ½), and leaves about 10⁻¹⁶ of rounding noise that tips t_near a hair past t_far. The library's own constants are now rationals for the same reason.
  • Surface geometry of the returned hits: each lies on the surface (max |coordinate| = 1), satisfies P · π = 0 for the plane vector of the face the normal names, has an outward normal, and the midpoint of each chord is strictly inside the cube — with a negative control (an interior point does not satisfy P · π = 0).
  • Transformations: a cube moved by M and hit by the equally moved ray gives the same t (three transformations); a cube scaled by 2 is hit at t = 3, 7; the normal on the +x face of a cube turned 45° about y is the turned vector.

Step 4 — Putting it together: only cubes

A room (one large cube, seen from the inside), a table made of five cubes (a top and four legs), and four boxes on it, two of them turned. The room has a checkered pattern and the table a striped wood pattern; the red box is slightly reflective.

# chapter 12: only cubes. A room (one big cube seen from inside), a table made of
# five cubes (a top and four legs), and four boxes on the table.
make a function called box takes xform, m returns s
  return set_material(set_transform(cube(), xform), m)
end

make a function called build_cube_scene returns w
  let room_m = with_pattern(material_with(color(1, 1, 1), (1/5), (4/5), 0, 200), set_pattern_transform(checkers_pattern(color((17/20), (4/5), (7/10)), color((1/2), (9/20), (19/50))), scaling((1/4), (1/4), (1/4))))
  let room = box(mat_mul(translation(0, 4, 0), scaling(8, 4, 8)), room_m)
  let wood = with_pattern(material_with(color(1, 1, 1), (1/5), (7/10), (3/20), 100), set_pattern_transform(stripe_pattern(color((11/20), (7/20), (1/5)), color((21/50), (13/50), (7/50))), mat_mul(rotation_y(pi() / 2), scaling((1/25), (1/25), (1/25)))))
  let top = box(mat_mul(translation(0, (7/5), 0), scaling((11/5), (1/10), (13/10))), wood)
  let leg1 = box(mat_mul(translation((39/20), (13/20), (11/10)), scaling((1/10), (13/20), (1/10))), wood)
  let leg2 = box(mat_mul(translation(-(39/20), (13/20), (11/10)), scaling((1/10), (13/20), (1/10))), wood)
  let leg3 = box(mat_mul(translation((39/20), (13/20), -(11/10)), scaling((1/10), (13/20), (1/10))), wood)
  let leg4 = box(mat_mul(translation(-(39/20), (13/20), -(11/10)), scaling((1/10), (13/20), (1/10))), wood)
  let red_box = box(mat_mul(translation(-(9/10), (9/5), (1/5)), mat_mul(rotation_y((2/5)), scaling((3/10), (3/10), (3/10)))), with_reflective(material_with(color((17/20), (3/25), (1/10)), (3/20), (7/10), (2/5), 200), (1/10)))
  let blue_box = box(mat_mul(translation((1/2), 2, -(3/10)), mat_mul(rotation_y(-(3/10)), scaling((1/5), (1/2), (1/5)))), material_with(color((3/20), (1/4), (17/20)), (3/20), (7/10), (2/5), 200))
  let gold_box = box(mat_mul(translation((13/10), (33/20), (2/5)), mat_mul(rotation_y((9/10)), scaling((3/20), (3/20), (3/20)))), material_with(color((9/10), (7/10), (1/10)), (3/20), (7/10), (2/5), 200))
  let green_box = box(mat_mul(translation(-(1/5), (17/10), -(7/10)), mat_mul(rotation_y((1/5)), scaling((1/5), (1/5), (1/5)))), material_with(color((1/10), (7/10), (3/10)), (3/20), (7/10), (2/5), 200))
  return [[room, top, leg1, leg2, leg3, leg4, red_box, blue_box, gold_box, green_box], point_light(point(0, 7, -4), color(1, 1, 1)), true]
end
# Chapter 12, "Putting It Together": a scene made only of cubes -- a room seen
# from inside, a table of five cubes, and four boxes on it.
include "../lib/spec.patlang"
include "../lib/png.patlang"
include "../lib/camera.patlang"
include "../lib/demo_scene.patlang"

let w = build_cube_scene()
let cam = set_camera_transform(camera(400, 200, pi() / 3), view_transform(point(0, (16/5), -(73/10)), point(0, (7/5), 0), vector(0, 1, 0)))
render_example(cam, w, "../out/ch12_cubes.png")
> tools/prender.sh examples/ch12_cubes.patlang
assembled 400x200 from 40 bands
rendered with 9 parallel processes (40 bands) in 525 s wall clock
A scene made only of cubes

Checking it independently

The recursive tracer learned cubes (the book's slab method, its own largest- component normal) and stripes. Every second pixel in each direction of the 400×200 image (20 000 pixels spread over the whole picture), recursion depth 5:

> powershell.exe -NoProfile -File tools/verify_recursive.ps1 out/ch12_cubes.png -Scene cubes -Stride 2
decoded by .NET: 400x200; pixels differing from the independent recursive tracer by more than 1 level: 0 (max difference 0); stride 2 in each direction, 20000 pixels checked

The book's closing question

The book asks how to avoid testing all six planes when the first comparisons already show a miss. This implementation stops early in one case only: an axis whose slab the ray cannot reach (a parallel ray outside it) returns a miss immediately. Comparing the running interval after each axis, and stopping as soon as t_near > t_far, would cut the work further for rays that miss diagonally; it is not done here.

Cost

About 3.5 ms per pixel for the cube scene with shadows (70 s at 200×100, measured alone): ten objects per ray, a room whose walls are hit from the inside, and the red box's reflection. The slab test itself is cheap, a handful of inner products per axis.

Cylinders and Cones

Two more shapes, both surfaces of revolution about the y axis, each optionally truncated (a minimum and a maximum y, both exclusive) and optionally closed with end caps. The algebra needs only one idea: the part of a vector perpendicular to the axis.

Step 1 — the rejection bivector

For a Euclidean vector v, the bivector e2 ∧ v has squared length x² + z² (the squared rejection of v from the axis), while the inner product e2 · v is y, the part along the axis. So the two surfaces are

cylinder   x² + z² = 1        ⇔   |e2 ∧ p|² = 1
cone       x² + z² = y²       ⇔   |e2 ∧ p|² − (e2 · p)² = 0

Putting the ray point o + t d into either form gives the quadratic's three coefficients as scalar parts of products of bivectors — exactly the book's a = dx² + dz², b = 2(ox dx + oz dz), c = ox² + oz² − 1 for the cylinder and the same with the y terms subtracted for the cone. A ray parallel to the cylinder's axis has a = 0 and can only hit the caps; a ray parallel to one half of a cone has a = 0 but b ≠ 0, and meets the other half once at t = −c / 2b.

An end cap is a plane vector π = e2 + y e∞, met with the same expression as the plane of Rays, spheres and planes, t = −(O · π) / (d · π); the hit counts when it lies within the radius there (1 for the cylinder, |y| for the cone). An infinite limit has no cap. That shared expression is now one function, ray_plane_t, used by the plane, the cube's slabs' counterpart in the caps, and both new shapes.

# a true IEEE infinity, the default limit of an unbounded cylinder or cone
make a function called infinity returns v
  return pow(10.0, 308) * 10
end

make a function called shape_min takes s returns v
  return s[6][0]
end

make a function called shape_max takes s returns v
  return s[6][1]
end

make a function called shape_closed takes s returns v
  return s[6][2]
end

# new shapes with changed limits / closedness (values are not mutated in place)
make a function called with_limits takes s, lo, hi returns s2
  return list_set(s, 6, [lo, hi, s[6][2]])
end

make a function called with_closed takes s, closed returns s2
  return list_set(s, 6, [s[6][0], s[6][1], closed])
end

# |e2 ^ v|^2: squared length of the part of the Euclidean vector v perpendicular to y
make a function called perp2 takes v returns n
  return v[1] * v[1] + v[4] * v[4]
end

# the polar form of perp2: (e2 ^ o) . (e2 ^ d) = o_perp . d_perp
make a function called perp_dot takes o, d returns n
  return o[1] * d[1] + o[4] * d[4]
end

# the cone's polar form: o_perp . d_perp - (e2 . o)(e2 . d); with o = d it is Q(d)
make a function called cone_form takes o, d returns n
  return perp_dot(o, d) - ga_vec_dot(ga_basis(1), o) * ga_vec_dot(ga_basis(1), d)
end

# t where the ray (conformal origin o, Euclidean direction dvec) meets the plane
# vector pv: -(O . pi) / (d . pi); false when the ray is parallel to the plane
make a function called ray_plane_t takes o, dvec, pv returns t
  let dp = ga_vec_dot(dvec, pv)
  if abs(dp) < epsilon() then
    return false
  end
  return 0 - ga_vec_dot(o, pv) / dp
end

# the real roots of a t^2 + b t + c, smaller first, or []
make a function called quadric_hits takes a, b, c returns ts
  let disc = b * b - 4 * a * c
  if disc < 0 then
    return []
  end
  let root = sqrt(disc)
  let t0 = (0 - b - root) / (2 * a)
  let t1 = (0 - b + root) / (2 * a)
  if t0 > t1 then
    return [t1, t0]
  end
  return [t0, t1]
end

# the intersections among ts whose y lies strictly between the shape's limits
make a function called limited_hits takes s, r, ts returns xs
  let oy = get_y(r[0])
  let dy = get_y(r[1])
  let xs = []
  let k = 0
  while k < ts.length do
    let y = oy + ts[k] * dy
    if s[6][0] < y and y < s[6][1] then
      let xs = list_push(xs, intersection(ts[k], s))
    end
    let k = k + 1
  end
  return xs
end

# add the end-cap hits of a closed shape to xs. A cap at height y has radius 1 for
# a cylinder and |y| for a cone; an infinite limit has no cap.
make a function called cap_hits takes s, r, xs returns out
  let out = xs
  let o = r[0]
  let d = r[1]
  let dy = get_y(d)
  if s[6][2] == false or abs(dy) < epsilon() then
    return out
  end
  let dx = get_x(d)
  let dz = get_z(d)
  let ox = get_x(o)
  let oz = get_z(o)
  let levels = [s[6][0], s[6][1]]
  let k = 0
  while k < 2 do
    let level = levels[k]
    if abs(level) < infinity() then
      # the plane at height `level`: t = -(o . pi) / (d . pi), with pi = e2 + level einf
      let t = 0 - (o[2] + o[8] * level - o[16] * level) / dy
      let radius2 = 1
      if s[5] == "cone" then
        let radius2 = level * level
      end
      let px = ox + dx * t
      let pz = oz + dz * t
      if px * px + pz * pz <= radius2 then
        let out = list_push(out, intersection(t, s))
      end
    end
    let k = k + 1
  end
  return out
end

make a function called cylinder_local_intersect takes s, r returns xs
  let ox = get_x(r[0])
  let oz = get_z(r[0])
  let dx = get_x(r[1])
  let dz = get_z(r[1])
  let a = dx * dx + dz * dz
  let xs = []
  if abs(a) >= epsilon() then
    let b = 2 * (ox * dx + oz * dz)
    let c = ox * ox + oz * oz - 1
    let xs = limited_hits(s, r, quadric_hits(a, b, c))
  end
  return cap_hits(s, r, xs)
end

make a function called cone_local_intersect takes s, r returns xs
  let ox = get_x(r[0])
  let oz = get_z(r[0])
  let dx = get_x(r[1])
  let dz = get_z(r[1])
  let yo = get_y(r[0])
  let yd = get_y(r[1])
  let a = dx * dx + dz * dz - yd * yd
  let b = 2 * (ox * dx + oz * dz) - 2 * yo * yd
  let c = ox * ox + oz * oz - yo * yo
  let xs = []
  if abs(a) < epsilon() then
    # the ray is parallel to one half of the cone: a t^2 vanishes, b t + c = 0, one point t = -c / b
    if abs(b) >= epsilon() then
      let xs = limited_hits(s, r, [0 - c / b])
    end
  else
    let xs = limited_hits(s, r, quadric_hits(a, b, c))
  end
  return cap_hits(s, r, xs)
end

# the normal of the cylinder at a point: the rejection e2 _| (e2 ^ p) = (x, 0, z),
# or straight up/down on an end cap
make a function called cylinder_local_normal takes s, p returns n
  let pv = tuple_evec(p)
  let dist = perp2(pv)
  let y = get_y(p)
  if dist < 1 and y >= s[6][1] - epsilon() then
    return vector(0, 1, 0)
  end
  if dist < 1 and y <= s[6][0] + epsilon() then
    return vector(0, -1, 0)
  end
  let rej = ga_lcontract(ga_basis(1), ga_outer(ga_basis(1), pv))
  return cga_direction(rej[1], rej[2], rej[4])
end

# the cone's normal: (x, -+|e2 ^ p|, z), the sign opposite to y (on the surface this
# is the reflection of p in the y axis, (x, -y, z)); caps as for the cylinder
make a function called cone_local_normal takes s, p returns n
  let pv = tuple_evec(p)
  let dist = perp2(pv)
  let y = get_y(p)
  if dist < s[6][1] * s[6][1] and y >= s[6][1] - epsilon() then
    return vector(0, 1, 0)
  end
  if dist < s[6][0] * s[6][0] and y <= s[6][0] + epsilon() then
    return vector(0, -1, 0)
  end
  let h = sqrt(dist)
  if y > 0 then
    let h = 0 - h
  end
  return cga_direction(get_x(p), h, get_z(p))
end

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

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

Step 2 — normals

The cylinder's normal is the rejection of the point, e2 ⌋ (e2 ∧ p) = (x, 0, z). The cone's is (x, ∓|e2 ∧ p|, z), with the sign opposite to y. On a cap the normal is straight up or down.the cone's normal flips sign at y:0

Step 3 — checks

Worked by hand: a ray through an endless tube, along its axis and beside it; within, below and at the open edge of a cut tube; down through both lids, and in through a lid and out through the side. For a cone: a ray through both halves, one parallel to a side (one hit, at t = −c/b), and one through a lid. Then each kind, cut and lidded, turned and moved, against its function. The algebra's forms and the coordinate forms agree on a fan of rays.

Further checks, sharing no code with what they check:

  • The quadratic from bivectors against exact coordinates: a, b, c computed with e2 ∧ v equal the book's formulas, in exact rationals.
  • Surface geometry: every returned hit satisfies the surface equation, and its normal is perpendicular to the surface (for the cone, to the tangent along the generator).
  • Transformed shapes: a cylinder moved and scaled, hit by an equally moved ray, gives the same t.

Step 4 — Putting it together

A closed striped column, an open red tube (you can see into it, and its inside is lit), and an ice-cream cone: a closed cone flipped upside down with a negative scale in y, topped with a reflective scoop.

# chapter 13: a closed striped column, an open tube (you can see into it), and an
# ice-cream cone -- a closed cone flipped with a negative scale -- with a scoop.
make a function called build_cylinder_scene returns w
  let floor_m = with_pattern(material_with(color(1, 1, 1), (1/10), (9/10), 0, 200), set_pattern_transform(checkers_pattern(color((9/10), (9/10), (9/10)), color((3/10), (3/10), (3/10))), scaling(2, 2, 2)))
  let floor_p = set_material(plane(), floor_m)
  let column_m = with_pattern(material_with(color(1, 1, 1), (1/10), (7/10), (3/10), 200), set_pattern_transform(stripe_pattern(color((1/10), (1/5), (17/20)), color((3/5), (3/5), (3/5))), scaling((1/10), (1/10), (1/10))))
  let column = set_material(set_transform(with_closed(with_limits(cylinder(), 0, 2), true), mat_mul(translation(-(3/2), 0, 1), scaling((3/5), 1, (3/5)))), column_m)
  let tube_m = with_reflective(material_with(color((4/5), (1/10), (1/10)), (1/10), (7/10), (1/2), 200), (1/10))
  let tube = set_material(set_transform(with_limits(cylinder(), 0, (6/5)), mat_mul(translation((3/2), 0, -(1/5)), scaling((1/2), 1, (1/2)))), tube_m)
  let wafer = with_pattern(material_with(color(1, 1, 1), (1/5), (7/10), (1/10), 100), set_pattern_transform(checkers_pattern(color((17/20), (13/20), (3/10)), color((3/5), (2/5), (3/20))), scaling((1/10), (1/10), (1/10))))
  let cone_s = set_material(set_transform(with_closed(with_limits(cone(), -1, 0), true), mat_mul(translation(0, 0, -1), scaling((2/5), -(4/5), (2/5)))), wafer)
  let scoop = set_material(set_transform(sphere(), mat_mul(translation(0, (19/20), -1), scaling((2/5), (2/5), (2/5)))), with_reflective(material_with(color(1, (3/5), (7/10)), (1/10), (7/10), (4/5), 200), (1/10)))
  return [[floor_p, column, tube, cone_s, scoop], demo_light(), true]
end
# Chapter 13, "Putting It Together": cylinders and a cone -- a closed striped
# column, an open tube, and an ice-cream cone with a scoop.
include "../lib/spec.patlang"
include "../lib/png.patlang"
include "../lib/camera.patlang"
include "../lib/demo_scene.patlang"

let w = build_cylinder_scene()
let cam = set_camera_transform(camera(400, 200, pi() / 3), view_transform(point(0, 2, -6), point(0, (9/10), 0), vector(0, 1, 0)))
render_example(cam, w, "../out/ch13_cylinders.png")
> tools/prender.sh examples/ch13_cylinders.patlang
assembled 400x200 from 40 bands
rendered with 9 parallel processes (40 bands) in 326 s wall clock
A column, a tube and an ice-cream cone

Checking it independently

The recursive tracer learned the book's cylinder and cone formulas (quadratic coefficients, exclusive limits, caps, the cone's −|y| normal), written on plain coordinates. Every second pixel in each direction, recursion depth 5:

> powershell.exe -NoProfile -File tools/verify_recursive.ps1 out/ch13_cylinders.png -Scene cylinders -Stride 2
decoded by .NET: 400x200; pixels differing from the independent recursive tracer by more than 1 level: 0 (max difference 0); stride 2 in each direction, 20000 pixels checked

Negative control: the same tracer against the Boxes, cylinders and cones image, which it should reject.

> powershell.exe -NoProfile -File tools/verify_recursive.ps1 out/ch12_cubes.png -Scene cylinders -Stride 4
decoded by .NET: 400x200; pixels differing from the independent recursive tracer by more than 1 level: 5000 (max difference 211); stride 4 in each direction, 5000 pixels checked

How it is checked

> v2_interp.exe tests/run.patlang --node shapes/cube --depth 2
[ ok ] Cubes
[ ok ]   Rays through faces, from inside, and past a corner
[ ok ]   A cube's normal is the axis of the face
[ ok ]   Against max(|x|, |y|, |z|) = 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 ]   Further checks, independent of the code they check
[ ok ]     Six-plane-vector slab test = the book's check_axis on
[ ok ]     Every hit lies on the surface: max |coordinate| = 1
[ ok ]     A transformed cube hit by the equally transformed ray: same t (3 transforms)
checks: 11 passed, 0 failed, 0 blocked, 0 skipped, 0 not run
ALL PASSED
> v2_interp.exe tests/run.patlang --node shapes/cylinder --depth 2
[ ok ] Cylinders
[ ok ]   An endless tube, one cut short, and one with lids
[ ok ]   Normals on the side and on the lids
[ ok ]   A new cylinder is endless and open
[ ok ]   Endless tube against x^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 ]   Cut short, against the tube between its limits
[ 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 ]   With lids, against the tube cut by two planes
[ 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 cylinder  (all, giving the same answer)
[ ok ]     naive: the part of each vector off the axis, in the algebra
[ ok ]     faster: the x and z coordinates
[ ok ]   Further checks, independent of the code they check
[ ok ]     The part of v perpendicular to the y axis, and along it, as plain numbers
[ ok ]     Every hit is on the wall (x^2 + z^2 = 1) or on a cap, inside its radius
[ ok ]     Every hit is on the wall (x^2 + z^2 = y^2) or on a cap, inside its radius
[ ok ]     A cylinder scaled to radius 2 is hit at z = -/+ sqrt(3) from x = 1
checks: 18 passed, 0 failed, 0 blocked, 0 skipped, 0 not run
ALL PASSED
> v2_interp.exe tests/run.patlang --node shapes/cone --depth 2
[ ok ] Cones
[ ok ]   Through both halves, along one side, and through a lid
[ ok ]   Normals on the upper and lower halves
[ ok ]   Both halves cut short, against x^2 + z^2 = y^2
[ 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 ]   With lids, 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 cone  (all, giving the same answer)
[ ok ]     naive: in the algebra
[ ok ]     faster: on the coordinates
checks: 10 passed, 0 failed, 0 blocked, 0 skipped, 0 not run
ALL PASSED

Graduate Attributes

Modelled on this page

  • Critical Thinker: Discrepancies between the book's formula and IEEE arithmetic behaviour are identified and tested with specific ray configurations.
  • Reflective: The decision to omit a further optimisation for diagonal misses is stated alongside the rationale for keeping the implementation simple.
  • Digitally Fluent: Performance metrics and rendering parameters are provided to contextualise the computational cost of the scene.

University of Reading Graduate Attributes framework.