How to determine Arc's Orientation in Java

142 views Asked by At

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 ?

2

There are 2 answers

2
Benvorth On

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
0
Nikos On

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      
}