Skip to main content
GameDev.net gamedev.net
🔒 Locked

Detecting winding of an arbitrry polygon

Started by thezbuffer Aug 12, 2008 at 11:19 PM 3 replies 1.4k views
Original Post
thezbuffer
thezbuffer
Given a closed 2d polygon how can I tell if its clockwise or counter clockwise? I'm feeding it to a triangulation routine which requires a certain winding. Right now the best I ahve come up with is feed it to the triangulation and throw away the result that has fewer triangles ;-) Seems like something I should be able to tell in advance and my google voodo has not come up with the right magic words.
ZMan
Nutter
Nutter
Calculate the normal from 2 edge vectors and compare it with the actual normal of the polygon: (((v0-v1) cross (v2-v1)) dot orig_normal) > 0.

Should work...
thezbuffer
thezbuffer
Which 2 edges though? I believe that only works for a convex polygon. For a concave one you might just be on an inside corner.




ZMan
thezbuffer
thezbuffer
Quote:
Original post by Nutter
hm, good point. This should do the trick then: http://local.wasp.uwa.edu.au/~pbourke/geometry/polyarea/

I wondered why you sent me to the area algorithm, until I read this one http://local.wasp.uwa.edu.au/~pbourke/geometry/clockwise/index.html#clockwise

Thats a great site - thanks.... google must pass him by (or rank him prety low)

ZMan

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.