There is no direct API for this purpose, however, you can draw a circle if you compute its center and radius.
The determinantal form of the equation of a circle is:
[tt]
| x²+y² x y 1|
|x1²+y1² x1 y1 1| = 0
|x2²+y2² x2 y2 1|
|x3²+y3² x3 y3 1|
[/tt]
where (x1, y1), (x2, y2) and (x3, y3) are three points which lie on the circle.
The above determinant can be expanded and rewritten in the following form.
a(x²+y²) + bx + cy + d = 0
The coefficients a, b, c and d can be evaluated by expanding the above determinant. (The expansion of the determinent is quite horrible!)
After determining these coefficients, the above equation can be rearranged in the standard or desired form of the circle, i.e.,
(x - p)² + (y - q)² = r²
Where (p, q) is the center of the circle and r is its radius. After p, q and r are known, the circle can be drawn easily.
See the following code which explains this method.
___
[tt]
Option Explicit
Dim Px(2) As Double, Py(2) As Double 'coordinates of the three points lying on the circle
Dim numPoints As Long 'number of points drawn
Private Sub Form_Load()
BackColor = 0
WindowState = vbMaximized
AutoRedraw = True
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
On Error Resume Next
If numPoints = 0 Then Cls
Px(numPoints) = X
Py(numPoints) = Y
Circle (X, Y), 45, vbRed
numPoints = numPoints + 1
If numPoints = 3 Then
numPoints = 0
Dim p As Double, q As Double, r As Double
SolveCircle Px(0), Py(0), Px(1), Py(1), Px(2), Py(2), p, q, r
Circle (p, q), r, vbGreen
End If
End Sub
'this procedure takes the coordinates of the three points lying on the circle and computes its center and radius
Sub SolveCircle(X1 As Double, Y1 As Double, X2 As Double, Y2 As Double, X3 As Double, Y3 As Double, p As Double, q As Double, r As Double)
Dim a As Double, b As Double, c As Double, d As Double
'equation of circle in the form
' a * (x ^ 2 + y ^ 2) + b * x + c * y + d = 0
'having...
a = (X1 * Y2 + X2 * Y3 + X3 * Y1) - (X2 * Y1 + X3 * Y2 + X1 * Y3)
b = (X2 * X2 * Y1 + X3 * X3 * Y2 + X1 * X1 * Y3) - (X1 * X1 * Y2 + X2 * X2 * Y3 + X3 * X3 * Y1) _
+ (Y2 * Y2 * Y1 + Y3 * Y3 * Y2 + Y1 * Y1 * Y3) - (Y1 * Y1 * Y2 + Y2 * Y2 * Y3 + Y3 * Y3 * Y1)
c = (Y1 * Y1 * X2 + Y2 * Y2 * X3 + Y3 * Y3 * X1) - (Y2 * Y2 * X1 + Y3 * Y3 * X2 + Y1 * Y1 * X3) _
+ (X1 * X1 * X2 + X2 * X2 * X3 + X3 * X3 * X1) - (X2 * X2 * X1 + X3 * X3 * X2 + X1 * X1 * X3)
d = (X1 * X1 + Y1 * Y1) * (X3 * Y2 - X2 * Y3) _
+ (X2 * X2 + Y2 * Y2) * (X1 * Y3 - X3 * Y1) _
+ (X3 * X3 + Y3 * Y3) * (X2 * Y1 - X1 * Y2)
'solving for radius and center of the circle
p = -b / 2 / a
q = -c / 2 / a
r = Sqr(p * p + q * q - d / a)
End Sub[/tt]
___
Run the above code and click on the form randomly. A circle will be drawn passing through the three points defining the circle.