antimony icon indicating copy to clipboard operation
antimony copied to clipboard

Applying an Offset to a Rounded Rectangle produces Bad Results

Open xxv opened this issue 10 years ago • 4 comments
trafficstars

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

xxv avatar May 30 '15 03:05 xxv

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

  • Not necessarily Euclidean
  • Chosen to be right shape at the zero crossing (but not necessarily everywhere else)

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?

mkeeter avatar May 30 '15 16:05 mkeeter

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

AstraLuma avatar May 30 '15 19:05 AstraLuma

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:

mkeeter avatar May 30 '15 20:05 mkeeter

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

AstraLuma avatar May 30 '15 22:05 AstraLuma