绘制角度范围为-360到360度的弧形

时间:2012-07-18 23:24:41

标签: c# wpf geometry trigonometry autocad

我在尝试绘制弧线时遇到了一些麻烦。基本上它的绘制应该与在AutoCAD中绘制3点弧的方式完全相同。我可以用-180度到360度的开始和结束角度绘制弧线,但是如果我试图超过-180,则弧线会翻转到+180度。我的问题是当角度超过-180时我需要弧线继续。除了计算开始和结束角度之外,我在代码中拥有一切(我认为)。在此先感谢您的帮助。这是我的代码:

private void DrawArc()
{
    //fyi linept is of type List<Point3D>();

    Point3D currentPoint = (Point3D)GetPoints(e);
    double rad;
    Point3D center = GetCenterOfCircle(linept.ElementAt(0), linept.ElementAt(1), currentPoint, out rad);
    PieSliceVisual3D circle = new PieSliceVisual3D();
    circle.Center = center;
    circle.OuterRadius = rad;
    circle.InnerRadius = circle.OuterRadius + 3;
    circle.StartAngle = (Math.Atan2(linept.ElementAt(0).Y - center.Y, linept.ElementAt(0).X - center.X) * 180 / Math.PI);
    circle.EndAngle = (Math.Atan2(currentPoint.Y - center.Y, currentPoint.X - center.X) * 180 / Math.PI);

    //I've also tried these next 4 lines to no avail
    double startAngle = (Math.Atan2(linept.ElementAt(0).Y - center.Y, linept.ElementAt(0).X - center.X) * 180 / Math.PI);
    circle.StartAngle = (startAngle > 0.0 ? startAngle : (360.0 + startAngle));
    double endAngle = (Math.Atan2(currentPoint.Y - center.Y, currentPoint.X - center.X) * 180 / Math.PI);
    circle.EndAngle = (endAngle > 0.0 ? endAngle : (360.0 + endAngle));
}

0 个答案:

没有答案