[metapost] Re: new is_clockwise routine

Laurence Finston lfinsto1 at gwdg.de
Sun Nov 27 13:23:31 CET 2005


On Sat, 26 Nov 2005, Giuseppe Bilotta wrote:

> Saturday, November 26, 2005 Laurence Finston wrote:
>
> > A more serious problem is determining whether the curve loops or changes
> > direction between two values of 't'.
>
> I don't understand why a curve looping is a problem. If a
> curve loops, it's still turning the same way, so if it's
> clockwise it remains clockwise.

You're right.  I was thinking of it being clockwise or counter-clockwise
and not crossing itself.  It occurred to me that one speaks of left-handed
and right-handed screws, so the term I was looking for was "parity", as
readers of Martin Gardner should know.

> Also, if the curve has an
> inflection then it most surely can't be clockwise (or
> counterclockwise).

Also true.  I can't think of an obvious test for this using
primitives or plain MP macros, except for checking the intersections
of subpaths.  However, I usually use MP as a black box, don't use a lot of
plain MP macros, and rarely define my own.

> At most, the problems arise when the curve has a cusp
> since, in this case both sides have the same direction (I'm
> talking about a single Bézier cubic with a cusp, not cusps
> generated by joining two cubics) even though the curve as a
> whole doesn't turn the same way all around.

According to my understanding of the matter, except where '&' is
used, there should be no cusps where two cubics are joined, because of the
high degree of continuity guaranteed by the definition of Bezier curves.

>
> Finding the direction at which a curve turns at any given
> point is easy: just find the sign of the cross product
>
> g'×g''
>
> which is also the sign of the curvature.

So much the better.

> (I'm talking about
> planar curves here, since in 3D it doesn't make sense at all
> to talk about clockwise vs counterclockwise,

I think it does, viz. the parity of screws.  I don't know the English
term, but in German "Schraubenflaechen" (screw surfaces) are an important
topic in constructive geometry.  In addition, one often has the case of
planar figures in 3-space --- I have it all the time.

> so a×b = a_x
> b_y - a_y b_x): if the cross product is positive, the curve
> turns counterclockwise, if it's negative it turns clockwise.
> Except of course at knots, but in this case g' = 0.

Just to clarify, for those who are not afficionados of spline curves:
This is a different kind of knot than the one I was
talking about.  More general spline curves use "weights", and even
more general ones also use "knots".  These are vectors of numerical values
that give increased local control.  That is, they increase or decrease the
"pull" exercised on the curve by the control points.  Knuth and Hobby
decided that Bezier curves, which invariant under affine transformations,
but not under projection, were sufficient for their purposes.

Laurence



More information about the metapost mailing list