[metapost] Re: d\'ej\`a vu or turningnumber, area et caetera

Boguslaw Jackowski bop at bop.com.pl
Fri Feb 4 12:57:40 CET 2005


Hello,

DL> The turning angle is plus or minus 180. You're probably thinking of
DL> the exterior angle, which might be 0 or 360 at a cusp.

Yes, indeed.

DL> A _turning angle_
DL> of 360 leaves the ant facing the same way and will never occur.

Thank you for pointing out my terminological slip and sorry for being
imprecise.

WL> What about my approach using the angles between PP+ and Q-Q to get the
WL> orientation (*not* the turningnumber)?  This would be even simpler
WL> since it doesn't need special code to avoid overflow.  Do you see any
WL> problems?

Needs some explanations and some coding -- see my next letter (it's under 
preparation since a few days but so called urgent matters hold me back 
from finishing it).

TH> The only actual use I know of is that the "counterclockwise" macro in
TH> MF uses turningnumber to reverse a path explicitly (because it would
TH> have raised an error while coloring pixels, otherwise).

I heavily exploit this feature in font programs -- the orientation of paths
is a very important factor.

TH> I don't like the use of Area() for turningnumbers, because Area()
TH> assumes that the path is extremely well-behaved. Under that condition,
TH> it is definately  easier (as Werner suggests) to calculate a sum of
TH> direction angles. Counting angles is also a lot faster.

I don't say that using `Area' is obligatory. ;-)

Nevertheless, counting angles is not a trifle. Actually, the optimized
Werner's `is_clockwise' function, even without taking into account the
crossing of control vectors (how should I name them?) is as effcient as
counting `Area' (slightly worse, but it can be improved).

In my font programs I use the `emergency_turningnumber' defined
as follows:

   vardef straighten_path(expr r) =
    for k=0 upto length r - 1: point k of r -- endfor
   if cycle r: cycle else: point infinity of r fi enddef;
   vardef emergency_turningnumber primary r =
    original_turningnumber(straighten_path(r))
   enddef;

It is three times faster than `Area' and `is_clockwise'; of course,
it also does not work with weird paths.

Cheers -- Jacko

Ps. Dan, how your name should be pronounced? (English spelling for my
     name would be Yatskovsky; hence also Yatsko ;-)

-- 
BOP s. c.
ul. Bora-Komorowskiego 24, 80-377 Gdansk, Poland
tel. (+48 58) 553 46 59,  fax (+48 58) 511 03 81
bop at bop.com.pl, http://www.bop.com.pl



More information about the metapost mailing list