CCW or CW ordering of the points of a generic polygon

  • Thread starter Thread starter Estanho
  • Start date Start date
  • Tags Tags
    Points Polygon
Click For Summary

Discussion Overview

The discussion revolves around the problem of ordering the vertices of a polygon, specifically in a counterclockwise (CCW) or clockwise (CW) manner. Participants explore methods for achieving this ordering, particularly in the context of polygons that may be concave and are already defined by their edges.

Discussion Character

  • Technical explanation
  • Exploratory
  • Debate/contested

Main Points Raised

  • Some participants note that sorting nodes of a concave polygon is ill-defined without further context, but inquire about ordering when the polygon is already defined by edges.
  • One participant suggests that ordering points CCW relative to the origin simplifies area calculations for the polygon.
  • Another participant describes an algorithm involving the calculation of the centroid and angles to order points, but acknowledges potential issues if the centroid lies outside the polygon.
  • A later reply introduces the concept of winding numbers in relation to the ordering of points, referencing a complex analysis text.
  • Further discussion includes the centroid calculation for triangles and the limitations of extending this to polygons with more than three sides, along with references to formulas for centroids and areas derived from Green's Theorem.

Areas of Agreement / Disagreement

Participants express various methods for ordering polygon vertices, but there is no consensus on a single approach. The discussion includes differing opinions on the applicability of centroid-based methods and the implications of polygon shape on these methods.

Contextual Notes

Some participants highlight limitations regarding the centroid's applicability to polygons with more than three vertices and the potential for pathological cases affecting the ordering process.

Estanho
Messages
14
Reaction score
2
Hi,
Suppose I have a data structure that models a polygon, by storing all the nodes of the given polygon, and their connections (i.e. edges).
I understand that sorting a set of nodes that may form a concave hull is ill-defined, as there could be many polygons that can be formed with those. But I'm asking about the case where the polygon is already defined by the edges. I'm attaching a drawing of such a polygon.
Is there an efficient and generic way to order the nodes of any such polygon, which may be concave, in ccw or cw?
 

Attachments

  • polygon.png
    polygon.png
    2.3 KB · Views: 673
Technology news on Phys.org
Estanho said:
Hi,
Suppose I have a data structure that models a polygon, by storing all the nodes of the given polygon, and their connections (i.e. edges).
I understand that sorting a set of nodes that may form a concave hull is ill-defined, as there could be many polygons that can be formed with those. But I'm asking about the case where the polygon is already defined by the edges. I'm attaching a drawing of such a polygon.
Is there an efficient and generic way to order the nodes of any such polygon, which may be concave, in ccw or cw?
It depends on what you want to do with these points after they're ordered.

If the points are ordered CCW with respect to the origin, it becomes much easier to calculate the area of the closed polygon, for instance.
 
The algorithm I use is the following:
(1) Find the centroid of the polygon - just the arithmetic mean of the points.
(2) Calculate the angle from the centroid to each point. I use the c++ atan2 function: angle = atan2(pointlist->y - cy, pointlist->x - cx).
(3) Order the points in increasing order by angle.

This works if the polygon is not too pathological, although it will probably fail if the centroid is outside the polygon.
 
phyzguy said:
The algorithm I use is the following:
(1) Find the centroid of the polygon - just the arithmetic mean of the points.
(2) Calculate the angle from the centroid to each point. I use the c++ atan2 function: angle = atan2(pointlist->y - cy, pointlist->x - cx).
(3) Order the points in increasing order by angle.

This works if the polygon is not too pathological, although it will probably fail if the centroid is outside the polygon.
You have stumbled upon the concept of winding numbers - an important concept in complex analysis. It is explained in Ahlfors (https://editorialdinosaurio.files.wordpress.com/2012/03/ahlfors_-_complex_analysis.pdf) page 114 ff.
 
phyzguy said:
The algorithm I use is the following:
(1) Find the centroid of the polygon - just the arithmetic mean of the points.
(2) Calculate the angle from the centroid to each point. I use the c++ atan2 function: angle = atan2(pointlist->y - cy, pointlist->x - cx).
(3) Order the points in increasing order by angle.

This works if the polygon is not too pathological, although it will probably fail if the centroid is outside the polygon.
The centroid location for a triangle is the arithmetic mean of the coordinates of the vertices, but I don't think this can be extended to a general polygon where n > 3.

This article contains formulas for calculating the area and the location of the centroid of a closed polygon of an arbitrary number of sides, n ≥ 3:

https://en.wikipedia.org/wiki/Polygon

The article doesn't mention that the centroid location in general is the arithmetic mean of the vertex coordinates.

These formulas and more can be derived by applying Green's Theorem in the plane to the integrals which define the area and first moment of area of a polygonal region. By careful description of the region under consideration, polygons with "holes" or similar non-convex regions can be evaluated, so long as there are no overlapping sides to the region.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 15 ·
Replies
15
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 9 ·
Replies
9
Views
11K
  • · Replies 2 ·
Replies
2
Views
7K
  • · Replies 15 ·
Replies
15
Views
2K
  • · Replies 2 ·
Replies
2
Views
5K