Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleDraw a circle through three points
Keywordscircle, points, draw circle
CategoriesGraphics
 
Find the perpendicular bisectors of the segments connecting the first two and last two points. See where the bisectors intersect. That's the center of the circle.

If the bisectors do not intersect, the three points are colinear so they do not define a circle.

 
Private Sub FindCircle(ByVal ax As Single, ByVal ay As _
    Single, ByVal bx As Single, ByVal by As Single, ByVal _
    cx As Single, ByVal cy As Single, ByRef ox As Single, _
    ByRef oy As Single, ByRef radius As Single)
Dim x1 As Single
Dim y1 As Single
Dim dx1 As Single
Dim dy1 As Single
Dim x2 As Single
Dim y2 As Single
Dim dx2 As Single
Dim dy2 As Single
Dim dx As Single
Dim dy As Single

    ' Get the perpendicular bisector of (x1, y1) and (x2,
    ' y2).
    x1 = (bx + ax) / 2
    y1 = (by + ay) / 2
    dy1 = bx - ax
    dx1 = -(by - ay)

    ' Get the perpendicular bisector of (x2, y2) and (x3,
    ' y3).
    x2 = (cx + bx) / 2
    y2 = (cy + by) / 2
    dy2 = cx - bx
    dx2 = -(cy - by)

    ' See where the lines intersect.
    ox = (y1 * dx1 * dx2 + x2 * dx1 * dy2 - x1 * dy1 * dx2 _
        - y2 * dx1 * dx2) _
        / (dx1 * dy2 - dy1 * dx2)
    oy = (ox - x1) * dy1 / dx1 + y1

    dx = ox - ax
    dy = oy - ay
    radius = Sqr(dx * dx + dy * dy)
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated