mkeeter / antimony

CAD from a parallel universe
2.11k stars 158 forks source link

Applying an Offset to a Rounded Rectangle produces Bad Results #31

Open xxv opened 9 years ago

xxv commented 9 years ago

Doing an Offset transform on a rounded rectangle reveals the construction of the rounded rectangle, which is a non-intuitive result.

mkeeter commented 9 years ago

This is because the offset function is a bit of a hack: it just slides up and down the distance field, and Antimony's distance fields are

Here's the distance field for a rounded rect: screen shot 2015-05-30 at 12 03 59 pm

To make offset well-behaved in all cases, we'd actually have to take level sets of a distance transform on the zero-crossing of the original field. Could be a fun blog post / conference paper -- any volunteers?

AstraLuma commented 9 years ago

We're just talking 2D paths, right? How does SVG/Inkscape do it?

mkeeter commented 9 years ago

It's a bit trickier than that. The rounded rectangle is represented internally by a function f(x,y,z) that returns a floating-point number. If f(x,y,z) < 0, then we're inside the shape; otherwise, we're outside. The edge of the rectangle is the set of points where f(x,y,z) = 0; the boundary is represented implicitly, rather than explicitely (as in SVGs and other boundary representations).

Doing CAD with implicit surfaces makes writing a geometry / CSG kernel very easy (unioning two shapes is just min(a(x,y,z), b(x,y,z))), but operations on specific features (like the edge of the rectangle) become harder to represent.

Further reading:

AstraLuma commented 9 years ago

Ah, hence the problems with interacting with other formats and difficulties with "free drawing" methods.