[metapost] METATYPE1 pen-stroking and tight curves

mskala at ansuz.sooke.bc.ca mskala at ansuz.sooke.bc.ca
Wed Sep 19 22:52:30 CEST 2012


On Wed, 19 Sep 2012, Daniel Henry Luecking wrote:
> Metapost has the unitvector command. The combination:
>   (unitvector(z1-z0)) dotprod (unitvector (z3-z2))
> will give the cosine of the angle difference. This is equivalent
> to (( z1-z0)/abs(z1-z0)) dotprod ((z3-z2)/abs(z3-z2))

I'm not sure that the actual angle difference (or its cosine, which is
equivalent when all I'm doing is taking a threshold on it) is really what
I want.  The formula I described also depends on the shape of the curve
beyond the angles at the endpoints, and seems to lead to better results.
However, it's not all that sensitive to the formula used, partly because
to trigger subdivision occasionally on some curves that don't require it
is not particularly harmful.

> For example, it is a theoretically possible for a path segment
>  to turn arbitrarily close to 360 degrees, which would be seen
> as a small angle difference between the directions at the ends.
> It is also theoretically possible to have a nearly 180 degree
> turn, followed by an inflection point and a nearly -180 degree
> turn.

Yes.  This won't catch all cases and I'm not sure that trying to is the
best use of resources.  Paths like the ones you describe are paths that
ought to be avoided for other reasons already.

> Finally, a large angle difference in a short space is bad. But
> on a long path, the start and end can have very different
> directions without a problem for the envelope.

It surprised me that in the formula I found to work best, overall size
isn't directly a factor at all.  It seems like if I scaled the whole
segment up by 10, then it *should* become less likely to be flagged, and
this formula, instead, is independent of scaling.  But every time I tried
to incorporate scale in any reasonable way (for instance, taking the
square root of the denominator so that it's less likely to trigger at
large scales), I ended up with infinite recursion trouble because the
halves, being smaller, would tend to have more of the tight-curve property
than their parent segment had.
-- 
Matthew Skala
mskala at ansuz.sooke.bc.ca                 People before principles.
http://ansuz.sooke.bc.ca/


More information about the metapost mailing list