Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed to determine if a list of points are all part of the same circle in VB.net
    text
    copied!<p>VB.NET</p> <p>My data is coming from an exported DXF file from various cad packages. When a circular arc (defined as a part of a true circle) is exported it is sometimes exported as a bunch of line segments rather than a circular arc.</p> <p>I have a list of points and I am trying to guess if they were derived from the same circle. Basically I iterate through all the points and use a method to find the center point of a circle from three points. My intention was to compare all the calculated center points generated and make a determination if they are close to each other.</p> <p>My first thought was that I could check to see if the center points are all equal but they have slight differences between them because of rounding and the underlying estimating routine that generates the point in the first place (I have no control over that).</p> <p>MY second was to check the standard deviation of the x and y values of the circumference points and compare that against the standard deviation of the x,y of the centers and make some judgement from that. VB.net does not seem to have a native stdev function and I am sometimes a bit lazy.</p> <p>Does anybody have a simple idea on how to determine if a list of points are all from the same circle?</p> <p>Here are my functions:</p> <p>To determine the center of a circle given three points:</p> <pre><code> 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 </code></pre> <p>And then to iterate the list of points and get a collection of centers. FYI...This function received a list of lines that have endpoints that are points so I do a bit of iterating to get all the correct points.</p> <pre><code> Public Function MakesCircle(lines As List(Of Line)) Dim points As New List(Of Point2D) If lines.Count &lt; 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 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload