Re: NSBezierPath clockwise?
Re: NSBezierPath clockwise?
- Subject: Re: NSBezierPath clockwise?
- From: Robert Clair <email@hidden>
- Date: Sat, 15 Oct 2005 11:58:55 -0400
Zeroth caveat:
You must know or determine that the polygon even *has* an
orientation. Self-intersecting polygons (figure-8) do not have an
orientation.
My raugh idea is:
a) I get a direction comparing 3 points of the curve. e.g. It's
clowise.
b) Then if at the right of each point I don't find the filled
area of
the polygon, I have to invert the direction thus it's anti-
clockwise.
Could this method work in any case?
Not as stated and fixing it up would make it difficult to implement.
Walking forward along a closed path that is oriented
counterclockwise, the points to the left in the immediate
neighborhood of your present location are in the interior. But how do
you turn this into an algorithm ? Even if you do it graphically, by
sampling pixels, the devil is in the phrase "immediate
neighborhood". The translation of that phrase is:
"A straight line segment from the sample interior point to your
location on the boundary isn't crossed by any other part of the
boundary."
You'd have to check for intersections of that line segment with each
segment of the boundary and keep track of the parity of the number of
intersections. Things like vertices potentially falling on the
segment make this hard to do correctly.
Any suggestion?
1) The archives. This has come up before.
2) Google, Google, Google - this is a standard elementary problem in
Computer Graphics/Computational Geometry.
The algorithm in brief form: find an extremal (topmost,etc) point.
Form the vectors going from that point to its neighbors on either
side and look at the sign of the cross product. An actual robust
piece of code requires some finesse to account for indistinct points,
three or more collinear points, etc.
.....Bob Clair
------------------------------------------------------------------------
--------
OK, put the gamba down slowly and nobody gets hurt.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden