[英]How to determine Arc's Orientation in Java
我正在使用以下代碼生成二維弧。
final Arc2D.Double arcPath = new Arc2D.Double();
arcPath.setArcByCenter(centerPoint.getX(), centerPoint.getY(), radius, fDXFArc.getStartAngle(), fDXFArc.getTotalAngle(), Arc2D.OPEN);
弧線在我的畫布上完美呈現,但我不知道它們是順時針還是逆時針。 有人可以分享檢測弧線方向的算法嗎?
我看到兩個提示always counterclockwise
(80%肯定):
首先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.
這只有在12 pm
為0 degrees
, clockwise
測量的度數或3 pm
, counterclockwise
測量的度數時才成立。
同一包中的第二個public void setAngles()
counterclockwise
測量度數:
* The arc will always be non-empty and extend counterclockwise
* from the first point around to the second point.
之后,在該類的所有函數中遵循相同的模式是有意義的。
如果您需要確定:詢問該課程的作者:
* @author Jim Graham
我實際上設法確定了我的弧線方向。 我只是將每個大於 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.