1

Most of the times, I determine contour orientation generating 2D points and computing the closed polygon area. Depending on the area value sign I can understand if the contour is oriented clockwise or not (see How to determine if a list of polygon points are in clockwise order?).

Would it be possible to do the same computations without generating 2D points? I mean, relying only on geometric curve properties?

We are interested in determining the orientation of contours like these ones without sampling them with 2D points.

EDIT: Some interesting solutions can be found here:

enter image description here

abenci
  • 8,422
  • 19
  • 69
  • 134
  • how exactly are your contours defined? what exactly is the input information you have? and what speaks against simply evaluate x (e.g. 5) points on these contours as 2D points and evaluate the orientation via the known procedure? – derHugo Nov 29 '21 at 13:10
  • We have all the geometric data for lines and arcs, we also know if the arc plane has Z-axis toward +1 or -1 (CW/CCW). – abenci Nov 30 '21 at 07:58
  • Late to the conversation, but the original link the OP posted wouldn't work for his examples if the arcs are not approximated by lines. The second example is a good one in that there are no line segments, just arcs. I think he's asking how do you get the orientation without line segments and the area formula? The only way I know is to approximate the arcs with line segments and then use the area formula. – Phineas Phred Feb 15 '22 at 18:38

2 Answers2

0

How are those geometric curves defined? Do you have an angle for them? The radius doesn't matter, only the difference between entry-angle and exit-angle of each curve.

In that case, a trivial idea crossing my mind is to just sum up all the angles. If the result is positive, you know you had more curves towards the right meaning it's a clockwise contour. If it was negative, then more curves were leftwards -> anti-clockwise contour. (assuming that positive angels determine a right-curve and vica versa)

AlexGeorg
  • 967
  • 1
  • 7
  • 16
  • of course as this is basically exactly what OP already linked in [How to determine if a list of polygon points are in clockwise order?](https://stackoverflow.com/questions/1165647/how-to-determine-if-a-list-of-polygon-points-are-in-clockwise-order) – derHugo Nov 29 '21 at 13:09
0

After thinking about this for awhile, for polygons that contain arcs I think there are three ways to do this.

One, is to break the arcs into line segments and then use the area formula as described above. The success of this approach seems to be tied to how close the interpolation of the arcs is as this could cause the polygon to intersect itself.

A quicker way than the above would be to do the interpolation of the arcs and then find a vertex in the corner (minimal Y, if tie minimal X) and use the sign of the cross product for that vertex. Positive CCW, negative CW. Again, this is still tied to the accuracy of the interpolation.

I think a better approach would be to find the midpoint of the arc and create two line segments, one from the beginning of the arc to the midpoint and another from the midpoint to the end of the arc and replace the arc with these line segments. Now you have a polygon with only line segments. Then you can add up all the normalized cross products of all the vertices. The sign will tell you the direction. Positive is counter-clockwise, negative is clockwise. In this case it doesn't matter if the polygon self-intersects.