Re: newbie-alert! Polygons
- From: Kenneth Sloan <KennethRSloan@xxxxxxxxx>
- Date: Mon, 05 Oct 2009 12:51:47 -0700
Carsten wrote:
HI all
I'm about to write a code that draws a polygon in directX 9. Only
primitive triangles are available to draw, so the polygon (an array of
2d vectors) are going to be split into into primitive triangles.
No swet for a purely concave polygon.
I'm considering running through all points and calculate the normal in
each point (the point the center with two closest neighbours). I've
given up zero constraints, and demand a clockwise/anticlockwise
constructed polygon ... that way, the normal will change sign for
points that lie convex in the polygon.- great!
The next step is .. still up for grabs.
One convex point in the polygon makes a good startingpoint for drawing
triangles (ie a fan) with the point as a member in all of them- great!
Two convex points are ideal to join and thus split the polygon into
two concave polygons.
My idea for multiple convex points are, to step through every second
point, check weather the mid-point-normal is ok, draw the triangle (if
ok), and take the point off the polygon. To iterate: Make a new
polygon with a reduced point-count + a set of redy drawable triangles.
I've noticed on my scetch, that the number of concave points shrink
through this procedure, and it'll have to converge toward 2.
Only snag is, that the ok-points that I take out to draw ... there is
no guarantee, that they won't end up covering a convex point and draw
outside the polygon. Though it may be a rare ocurrence, I thought that
you guys have been presented with the problem before and maybe have a
less clumsy way, or even ... the right way ;o)
Cheers
I used to mail through OutlookExpress
... so, this message may wind up 'somewhere'
... with a life of its own
You have (almost) re-invented "ear-clipping". Move around the polygon until you reach a convex vertex. CHECK to be sure that painting the triangle (previous vertex, THIS convex vertex, next vertex) will not obscure any other vertex. If so, paint it, it not, keep going.
Once you get it working, you can start worrying about making it fast (fast enough for YOUR application).
Google "ear clipping triangulating polygons" and you should find many discussions of this algorithm.
There are other, more THEORETICALLY appealing methods - but my standard advice is that no one should even consider these until after ear-clipping is already working and you are getting some real work done with it.
If you are desperate, I can probably dig up some ancient C code - please poke me off-list if you really want 20 year old C code.
--
Kenneth Sloan KennethRSloan@xxxxxxxxx
Computer and Information Sciences +1-205-932-2213
University of Alabama at Birmingham FAX +1-205-934-5473
Birmingham, AL 35294-1170 http://KennethRSloan.com/
.
- References:
- newbie-alert! Polygons
- From: Carsten
- newbie-alert! Polygons
- Prev by Date: Re: newbie-alert! Polygons
- Next by Date: Re: newbie-alert! Polygons
- Previous by thread: Re: newbie-alert! Polygons
- Next by thread: Newbie-Alert Polygons
- Index(es):
Relevant Pages
|
Loading