1

I am generating 2D arcs using the following code.

final Arc2D.Double arcPath = new Arc2D.Double();
arcPath.setArcByCenter(centerPoint.getX(), centerPoint.getY(), radius, fDXFArc.getStartAngle(), fDXFArc.getTotalAngle(), Arc2D.OPEN);

The arcs are perfectly rendered on my Canvas but I do not know if they are Clockwise or Counter Clockwise. Can someone share the algorithm to detect the arc's orientation ?

Nikos
  • 67
  • 5
  • Nice riddle :-) – Benvorth Jun 07 '22 at 14:33
  • @user16320675 To better understand my problem use an arc starting at 0 degrees and ending at 180degrees. Is it CW or CCW ? – Nikos Jun 13 '22 at 15:44
  • there are two possible arcs starting at 0° and ending at 180° (or almost any other angles,) it is your choice - I gave the answer for posted code : if `getTotalAngle()` returns a negative value, the arc is CW; if the value is positive, the arc is CCW - I cannot see what `getTotalAngle()` is actually calculating/returning. – user16320675 Jun 13 '22 at 15:56

2 Answers2

0

I see two hints for always counterclockwise (80% sure):

First java.awt.geom.Arc2D itself tells in it's class description:

* The angles are specified relative to the non-square
* framing rectangle such that 45 degrees always falls on the line from
* the center of the ellipse to the upper right corner of the framing
* rectangle.

This can only be true if 0 degrees are at 12 pm and degrees measured clockwise or 3 pm and degrees measured counterclockwise.

Second public void setAngles() in the same package measure degrees counterclockwise:

* The arc will always be non-empty and extend counterclockwise
* from the first point around to the second point.

following that it would make sense to follow the same pattern in all functions of that class.

If you need to be sure: Ask the author of that class:

 * @author      Jim Graham
Benvorth
  • 7,416
  • 8
  • 49
  • 70
-1

I actually manage to determine my Arcs direction. I just splitted every arc that is larger than 180degrees to 2 smaller arcs and I use the following code

Point startPoint = arc.getBorderPoint(EBorderPoint.StartPoint);
Point endPoint = arc.getBorderPoint(EBorderPoint.EndPoint);
Point centerPoint = arc.getBorderPoint(EBorderPoint.CenterPoint);

final double result = (endPoint.getX() - startPoint.getX()) * (centerPoint.getY() - startPoint.getY()) - (endPoint.getY() - startPoint.getY()) * (centerPoint.getX() - startPoint.getX());
boolean isClockWise = result > 0 ? false : true;

if (result == 0)
{
    // Since I splitted the large arcs to 2 smaller arcs 
    // the code will never go to this if statement      
}
Nikos
  • 67
  • 5