我有一个简单的图表,用户可以在其中确定弧度的开始和结束方向。然后该控件使用 OnRender
的重写来绘制图表。我正在使用 StreamGeometryContext.ArcTo
绘制弧线。此方法有一个 IsLargeArc
属性,它确定如何绘制圆弧(> 180 度 (PI) 为真,< 180 度为假)。我正在根据工作正常的条件确定此值:
//Rule does not exceed 180 degrees in direction (radian), IsLargeArc= False else true
if (Start < Math.PI && (End - Start) < Math.PI || //currently unknow condition in here to deal with < PI when start angle is > then end angle?)
{
//IsLargeArc = false;
}
else
{
//IsLargeArc= true;
}
问题出现在开始 < 结束时。例如从 270 度到 120 度。在这种情况下,我需要一个条件来满足超过 180 度 (PI) 的角度。数学不是我的强项。我想我需要将 PI*2 添加到末尾,然后以某种方式比较这两个值,但不确定如何实现这一点?
最佳答案
好吧,您可以在end
(或开始;根据方向)角度添加一个完整的圆,例如:
if (start < end)
start += 2 * Math.PI; //full circle in radians.
这样,您将在结束角上添加一个完整的圆,这不会改变绘图的位置,并且如果您减去它们,则会得到一个有效且正确的角度(start - end
).
尽管我必须说,我希望有一个开始 > 结束
条件。
如果 start > end
或相反,这会告诉您一些关于方向的信息。
关于c# - 两个角度的弧度差?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35033253/