Skip to main content

quad_deviation

Function quad_deviation 

Source
pub fn quad_deviation(a: Point3, b: Point3, c: Point3, d: Point3) -> Scalar
Expand description

How far the bilinear patch over one wall quad can sit from the two triangles loft splits it into.

The quad joins ring points a -> b on one station to c -> d on the next, and loft cuts it along the diagonal a-d into (a, b, d) and (a, d, c). The patch B(x, y) = (1-y)((1-x)a + xb) + y((1-x)c + xd) is the surface the chords between the two stations span: its row at fixed x is the chord between the two placements of one profile point, which is why the sweeps bound the exact surface against it. Every bound below holds pointwise, so the smallest is returned:

  • |T| / 4 with the twist T = a - b - c + d. On the half x >= y, B - L = -y(1-x) T where L is the point of (a, b, d) with the same barycentric weights, and y(1-x) <= 1/4 there; the other half is symmetric. Always valid.
  • |b - a|: B is within (1-y)x|b - a| of the point (1-y)a + y((1-x)c + xd) of triangle (a, d, c). Likewise |c - a| against (a, b, d). These make a quad that collapses to a triangle on an axis (a ring point on a revolution axis) exact.
  • 2|d - c|: B is within xy|d - c| of the point (1-y)((1-x)a + xb) + yc of the plane triangle (a, b, c), and moving that triangle’s c to d moves the point by at most |d - c|. Likewise 2|d - b|.
  • The flattening bound. Take a plane with unit normal n and heights h(p) = n.p - k, project the corners onto it, and suppose the projected quad a', b', d', c' is convex. The projected patch is a convex combination of the projected corners, so it lies in that quad, which the two plane triangles (a', b', d'), (a', d', c') cover: each B(x, y) has a point Z there with Z = B(x, y) in the plane. Lifting Z back with the same weights gives a point of (a, b, d) or (a, d, c), and the two heights are weighted means of corner heights, so the distance is at most the spread of the corner heights. Two planes are used. The plane through a, b, c leaves only d off it, at the height g: bound |g|. The plane parallel to both diagonals, halfway between them, puts a, d at e and b, c at -e, with 2|e| the distance between the diagonals: bound 2|e|, half of |g| for a twisted quad (where |g| = 4|e|). A planar convex quad, the wall a revolution builds about an axis in the profile’s plane, gets 0.

The convexity test runs in floating point with a relative slack of 1e-12: a quad that fails it by less leaves an uncovered sliver some 1e-12 of its size wide, far below any chord budget.