pub fn quad_deviation(a: Point3, b: Point3, c: Point3, d: Point3) -> ScalarExpand 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| / 4with the twistT = a - b - c + d. On the halfx >= y,B - L = -y(1-x) TwhereLis the point of(a, b, d)with the same barycentric weights, andy(1-x) <= 1/4there; the other half is symmetric. Always valid.|b - a|:Bis 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|:Bis withinxy|d - c|of the point(1-y)((1-x)a + xb) + ycof the plane triangle(a, b, c), and moving that triangle’sctodmoves the point by at most|d - c|. Likewise2|d - b|.- The flattening bound. Take a plane with unit normal
nand heightsh(p) = n.p - k, project the corners onto it, and suppose the projected quada', 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: eachB(x, y)has a pointZthere withZ = B(x, y)in the plane. LiftingZback 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 througha, b, cleaves onlydoff it, at the heightg: bound|g|. The plane parallel to both diagonals, halfway between them, putsa, dateandb, cat-e, with2|e|the distance between the diagonals: bound2|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.