# [metapost] Pen stroking and tight curves

mskala at ansuz.sooke.bc.ca mskala at ansuz.sooke.bc.ca
Mon Oct 22 04:39:49 CEST 2012

```On Sun, 21 Oct 2012, xiolyxioly wrote:
> It seems to me that the methods being proposed are all somewhat heuiristic.
> I don't think it's very difficult to do this "rigorously".

> The curvature of a Bezier cubic curve R(t) is a continuous function. We are
> looking for "tight" regions where it's value is less than the pen radius

The problem isn't "find where on the curve the radius is less than the pen
radius" but "find a cubic spline that approximates the ideal envelope."
We're already in Heuristics Land as soon as we want the result to be a
cubic spline, because the ideal envelope is a higher-order curve.

> I have similar thoughts on the problem of detecting inflexions. Again, it's
> just a problem of finding the zeros of a real-valued function. I think there
> can be no more than 2 inflexions on a Bezier cubic. Again, CAD systems
> frequently do this computation, so code exists.

Indeed, Metapost code for it is in this commit:
http://sourceforge.jp/projects/tsukurimashou/svn/view/trunk/mp/intro.mp?root=tsukurimashou&r1=332&r2=333

A few tricky numerical cases have been tweaked since that version, but
the linked page contains an interface through which the current version is
available, and looking at the file as a whole would make it harder to see
the relevant bits.
--
Matthew Skala
mskala at ansuz.sooke.bc.ca                 People before principles.
http://ansuz.sooke.bc.ca/
```