Polygon 2d - how to detect clockwise/counter clockwise orientation?

tlehmann

New member
Joined
Mar 14, 2017
Messages
2
Hi,

for private fun I'm programming some 2d math: Vector2d, Point2d, Line2d and Polygon2d.
I'm confronted with a problem related detecting whether the list of ordered points in
a 2d polygon are clockwise or counter clockwise oriented
. I'm not sure how to do it.
Some questions to this:

a) Clockwise logical means walking around a center point.
I found one this article: https://en.wikipedia.org/wiki/Centroid#Centroid_of_polygon
The area calculation I have implemented yet.
Anyway I want to be sure that this direction is essential for clockwise detection, is it?

b) I always hear about conditions relating thise like that a polygon should be simple. Does it mean
that there is no algorithm that ensures calculation for every 2d polygon type (convex+concav+complex)?

c) Also I would have the centroid point I'm not sure how to detect that a polygon is clockwise.
Using a function I also have is: turned_left to get a left vertical to current line segement I can
detect that the centroid is left of or right of current line segment (basically with scalar product).

Clockwise would mean that the point should be right of each line segement, right?
For a convex polygon I can imagine that this might work but I'm pretty sure for a concav one the
condition is cannot be sufficient. Any hints on how to forward with this?

Any help, comments, links are appreciated,

Thanks,

Thomas
 
ok, somtimes you have to post something that you read things again and again.

Looking again at the article I posted I have seen a text saying that the area is
negative when the points are ordered clockwise. I have been able
to verify it with unittests for a simple convex and a simple concav polygon
(examples: a square and a square with one corner moved to the middle).

Still remains:

- does that work for all convex and concav 2d polygons?
- does it also work for complex 2d polygons?

Kind regards,
Thomas


Hi,

for private fun I'm programming some 2d math: Vector2d, Point2d, Line2d and Polygon2d.
I'm confronted with a problem related detecting whether the list of ordered points in
a 2d polygon are clockwise or counter clockwise oriented
. I'm not sure how to do it.
Some questions to this:

a) Clockwise logical means walking around a center point.
I found one this article: https://en.wikipedia.org/wiki/Centroid#Centroid_of_polygon
The area calculation I have implemented yet.
Anyway I want to be sure that this direction is essential for clockwise detection, is it?

b) I always hear about conditions relating thise like that a polygon should be simple. Does it mean
that there is no algorithm that ensures calculation for every 2d polygon type (convex+concav+complex)?

c) Also I would have the centroid point I'm not sure how to detect that a polygon is clockwise.
Using a function I also have is: turned_left to get a left vertical to current line segement I can
detect that the centroid is left of or right of current line segment (basically with scalar product).

Clockwise would mean that the point should be right of each line segement, right?
For a convex polygon I can imagine that this might work but I'm pretty sure for a concav one the
condition is cannot be sufficient. Any hints on how to forward with this?

Any help, comments, links are appreciated,

Thanks,

Thomas
 
Top