【发布时间】:2013-12-15 01:57:58
【问题描述】:
VB.NET
我的数据来自各种 cad 包中导出的 DXF 文件。导出圆弧(定义为真实圆的一部分)时,有时会导出为一组线段而不是圆弧。
我有一个点列表,我试图猜测它们是否来自同一个圆。基本上我遍历所有点并使用一种方法从三个点中找到圆的中心点。我的目的是比较所有生成的计算中心点,并确定它们是否彼此接近。
我的第一个想法是,我可以检查中心点是否都相等,但它们之间存在细微差异,因为舍入和首先生成该点的基础估计例程(我无法控制) )。
我的第二个是检查圆周点的 x 和 y 值的标准偏差,并将其与中心的 x,y 的标准偏差进行比较,并据此做出一些判断。 VB.net好像没有原生的stdev函数,我有时候有点懒。
有人对如何确定点列表是否都来自同一个圆有一个简单的想法吗?
这是我的功能:
给定三个点来确定圆心:
Public Function getCenter(p1 As Point2D, p2 As Point2D, p3 As Point2D) As Point2D
Dim yDelta_a As Double = p2.Y - p1.Y
Dim xDelta_a As Double = p2.X - p1.X
Dim yDelta_b As Double = p3.Y - p2.Y
Dim xDelta_b = p3.X - p2.X
Dim center As New Point2D
Dim aSlope As Double = yDelta_a / xDelta_a
Dim bSlope As Double = yDelta_b / xDelta_b
center.X = (aSlope * bSlope * (p1.Y - p3.Y) + bSlope * (p1.X + p2.X) - aSlope * (p2.X + p3.X)) / (2 * (bSlope - aSlope))
center.Y = -1 * (center.X - (p1.X + p2.X) / 2) / aSlope + (p1.Y + p2.Y) / 2
Return center
End Function
然后迭代点列表并获取中心集合。仅供参考...此函数接收到具有端点为点的线列表,因此我进行了一些迭代以获取所有正确的点。
Public Function MakesCircle(lines As List(Of Line))
Dim points As New List(Of Point2D)
If lines.Count < 2 Then
Return False
Else
//Get points from lines
For i As Int16 = 0 To lines.Count - 2
points.Add(lines(i).StartPoint)
Next
points.Add(lines.Last.StartPoint)
End If
//"Prime the pump" for the center calculation loop
Dim centers As New List(Of Point2D)
Dim a As Point2D = points(0)
Dim b As Point2D = points(1)
Dim c As Point2D = points(2)
//Calc all the centers
For i As Int16 = 3 To lines.Count - 1
centers.Add(getCenter(a, b, c))
a = b
b = c
c = points(i)
Next
//This is where I need logic to determine if the points all actually belong to the same circle
Return True
End Function
【问题讨论】:
-
离开头顶(所以可能有缺陷!):找到具有最大和最小 y 值的点,以及具有最大和最小 x 值的点。计算“平均”中心点。然后计算该中心所有点的标准偏差距离?
-
您的函数预计使用多少数据?圆圈是来自计算机生成的圆圈(因此唯一的错误是四舍五入),还是来自某种测量或用户输入?
-
三个或更多点,最多几百个。我的数据来自各种 cad 包中导出的 DXF 文件。导出圆弧(定义为真实圆的一部分)时,有时会导出为一组线段而不是圆弧。 DXF 转换例程也可以将样条线导出为一组线段(称为折线)。我需要区分从圆生成的折线和从样条生成的折线之间的区别。