我必須在圓邊緣的兩點之間畫一條弧線。假設弧線總是以盡可能短的距離繪制(edit2:掃描標志設定為0),我需要知道弧線是順時針還是逆時針繪制。
我得到以下輸入:
- 起點(point1)
- 終點(point2)
- 中心點
- 半徑

Edit1:這個問題與 svg 中的弧有關。因此它屬于編程。
uj5u.com熱心網友回復:
答案是 SVG 同時支持順時針和逆時針弧。您可以通過更改弧 (A) 命令中的“掃描”標志在它們之間切換。
如果您想了解 SVG 弧的作業原理,可以查看SVG 規范的路徑弧部分。
uj5u.com熱心網友回復:
描述了資料后,您可以找到更小的圓弧 - CCW 或 CW 圓弧。
只需檢查向量叉積的符號point1-center并point2-center顯示最短弧方向:
cp = (p1.x-c.x)*(p2.y-c.y)-(p1.y-c.y)*(p2.x-c.x)
因為cp>0您必須將sweep引數設定為 0,否則設定為 1 (反之亦然),而large-arc-flag應始終為 0。
uj5u.com熱心網友回復:
在與數學家討論后,我找到了答案,并在此基礎上撰寫了以下代碼:
public static bool IsClockWise(Point point1, Point point2, Circle circle)
{
var dxPoint1 = point1.X - circle.CenterX;
var dyPoint1 = point1.Y - circle.CenterY;
var dxPoint2 = point2.X - circle.CenterX;
var dyPoint2 = point2.Y - circle.CenterY;
double thetaPoint1 = 0, thetaPoint2 = 0;
if (dxPoint1 > 0 && dyPoint1 >= 0)
thetaPoint1 = Math.Asin(dyPoint1 / circle.Radius);
else if (dxPoint1 <= 0 && dyPoint1 > 0)
thetaPoint1 = Math.PI - Math.Asin(dyPoint1 / circle.Radius);
else if (dxPoint1 < 0 && dyPoint1 <= 0)
thetaPoint1 = Math.Abs(Math.Asin(dyPoint1 / circle.Radius)) Math.PI;
else if (dxPoint1 >= 0 && dyPoint1 < 0)
thetaPoint1 = 2 * Math.PI - Math.Abs(Math.Asin(dyPoint1 / circle.Radius));
if (dxPoint2 > 0 && dyPoint2 >= 0)
thetaPoint2 = Math.Asin(dyPoint2 / circle.Radius);
else if (dxPoint2 <= 0 && dyPoint2 > 0)
thetaPoint2 = Math.PI - Math.Asin(dyPoint2 / circle.Radius);
else if (dxPoint2 < 0 && dyPoint2 <= 0)
thetaPoint2 = Math.Abs(Math.Asin(dyPoint2 / circle.Radius)) Math.PI;
else if (dxPoint2 >= 0 && dyPoint2 < 0)
thetaPoint2 = 2 * Math.PI - Math.Abs(Math.Asin(dyPoint2 / circle.Radius));
if (thetaPoint1 > thetaPoint2)
{
return !(thetaPoint1 - thetaPoint2 <= Math.PI);
}
return thetaPoint2 - thetaPoint1 <= Math.PI;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/454216.html
