简体   繁体   English

如何在 Java 中确定 Arc 的方向

[英]How to determine Arc's Orientation in Java

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 ?有人可以分享检测弧线方向的算法吗?

I see two hints for always counterclockwise (80% sure):我看到两个提示always counterclockwise (80%肯定):

First java.awt.geom.Arc2D itself tells in it's class description:首先java.awt.geom.Arc2D本身在它的类描述中说明:

* 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 .这只有在12 pm0 degreesclockwise测量的度数或3 pmcounterclockwise测量的度数时才成立。

Second public void setAngles() in the same package measure degrees counterclockwise :同一包中的第二个public void setAngles() 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

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我只是将每个大于 180 度的弧分成 2 个较小的弧,我使用以下代码

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      
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM