Teen Programmers Unite  
 

 

Return to forum top

Counter-clockwise

Posted by taubz [send private reply] at October 03, 2001, 04:36:51 PM

Hiya... Does anyone know how to determine if an ordering of 2D points that form a polygon is in clockwise or counterclockwise order? Maybe the sum of the angles between neighboring segments is positive if clockwise?

Thanks.

- taubz

Posted by Psion [send private reply] at October 03, 2001, 10:23:01 PM

A formula from an algorithms book:

z = (x_i - x_0)(y_c - y_0) - (y_i - y_0)(x_c - x_0)

z > 0 iff p_i (with coords x_i and y_i) is clockwise from p_c with respect to p_0.... looks like a cross-product :-)

Posted by gian [send private reply] at October 04, 2001, 03:44:12 AM

* gian takes one look, goes insane and starts running into walls, head-first.

Posted by taubz [send private reply] at October 04, 2001, 12:31:28 PM

Duh... okay.... is that formula for finding the clockwise-nature (?) of a polygon or just for two points? I think that's just for two line segments joined at a point (if it isn't, then I don't follow the formula), which doesn't tell you anything about the polygon.

Thanks, but try again? I'll try gamedev.net, not that this is for a game.

- taubz

Posted by Psion [send private reply] at October 04, 2001, 07:54:50 PM

I think you just pick one point as the start and compare the pairs of adjacent points afterward with that first point as the reference.

Posted by taubz [send private reply] at October 05, 2001, 11:28:18 AM

Well, either way, I found the algorithm on gavedev.net... it wasn't as simple as that formula. Thanks, tho.

- taubz

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.