0

我正在尝试使用 Helix 3D 工具包制作用户定义的弧线。用户选择圆弧上的 3 个点(起点、中间、终点),程序找到圆心并从起点到终点绘制圆弧。我的问题是我不擅长数学,而且我在完成这项工作时遇到了问题。我的主要问题是获取开始和结束角度并让它准确地绘制各种尺寸的弧线。任何帮助表示赞赏。这是我的代码:

private void Draw_Arc(object sender, MouseButtonEventArgs e)
    {
            linept = new List<Point3D>();
            linept.Add(startPoint);
            linept.Add(endPoint);
            linept.Add((Point3D)GetPoints(e));
            LinesVisual3D line = new LinesVisual3D();
            line.Thickness = 2;
            line.Color = Colors.Blue;
            line.Points = linept;
            port.Children.Add(line);

            double startAngle, sweepAngle;
            Point3D center = GetCenterOfArc(linept.ElementAt(0), linept.ElementAt(1), linept.ElementAt(2));
            GetAngles(linept.ElementAt(0), linept.ElementAt(1), linept.ElementAt(2), out startAngle, out sweepAngle);
            circle = new PieSliceVisual3D();
            double RadiusX = Math.Abs(startPoint.X - center.X);
            double RadiusY = Math.Abs(startPoint.Y - center.Y);
            circle.Center = center;
            if (RadiusX >= RadiusY)
                circle.OuterRadius = RadiusX;
            else
                circle.OuterRadius = RadiusY;
            circle.InnerRadius = circle.OuterRadius + 3;
            circle.StartAngle = (180 / Math.PI * Math.Atan2(startPoint.Y - circle.Center.Y, startPoint.X - circle.Center.X));
            circle.EndAngle = (180 / Math.PI * Math.Atan2(linept.ElementAt(2).Y - circle.Center.Y, linept.ElementAt(2).X - circle.Center.X));
            port.Children.Add(circle);
    }
4

1 回答 1

2

我认为你必须知道圆心才能知道圆弧的起始和结束角度。

假设你只有三个点,并且你想找到一个穿过所有三个点的圆,你基本上有三个带有三个变量的方程:

(x-x0)^2 + (y-y0)^2 = R^2

(x-x1)^2 + (y-y1)^2 = R^2

(x-x2)^2 + (y-y2)^2 = R^2

如果您尝试自己编程并且具有平均数学知识,则解决该问题可能会有些棘手,但是您可以使用矩阵相当容易地做到这一点。在这里阅读一些信息。

解完这三个方程后,你应该有 X、Y、R。

X 和 Y 将是圆的中心点,R - 它的半径。

现在,据我记得,他们从正 X 轴开始计算弧度,向上。所以你需要计算两条线之间的角度——从中心到浮点的线,以及从中心点到“无限”右边的线。您可能只是谷歌“计算两条线之间的角度”。为您的起点和终点重复该过程,将为每个人提供各自的进入/退出角度。

中间点实际上不再使用,但半径是。您只需将其设置为半径即可。

我还没有真正实现任何东西 - 只是给你一个公平的方向。(我敢打赌,有一个更清洁、更易于使用的解决方案)

于 2012-07-17T00:51:55.517 回答