Visual Basic's Circle method can draw pie slices but it's pretty confusing. If either the start or end angle is negative, the routine draws a radius from the center of the circle to that position on the arc and then treats the angle as if it were positive. Note that zero isn't negative so it will not draw a radius to the angle zero. You can work around this by using a small negative number such as -0.000001. Note also that the method always draws counter clockwise.
To draw an pie slice with both radii drawn, figure out what angles you want to use. Use only positive angles now. If you want to draw a pie slice smaller than Pi radians (180 degrees), put the smaller angle first in the argument list. If you want to draw a slice that covers more than half the circle, put the larger angle first.
Now put a minus sign in front of both angles. If one of the angles is 0, change it to -0.000001.
This program shows several examples.
|
Private Sub Form_Load()
Const R As Double = 50
Const GAP As Double = 5
Dim X As Double
Dim Y As Double
AutoRedraw = True
' Northeast wedge.
X = R
Y = R
FillStyle = vbFSTransparent
Circle (X, Y), R, vbWhite
FillStyle = vbFSSolid
Circle (X, Y), R, vbRed, -PI / 6, -PI / 6 * 2
' Everything else.
X = X + 2 * R + GAP
FillStyle = vbFSTransparent
Circle (X, Y), R, vbWhite
FillStyle = vbFSSolid
Circle (X, Y), R, vbRed, -PI / 6 * 2, -PI / 6
' East wedge.
Y = Y + 2 * R + GAP
X = R
FillStyle = vbFSTransparent
Circle (X, Y), R, vbWhite
FillStyle = vbFSSolid
Circle (X, Y), R, vbRed, -PI * 1.75, -PI * 0.25
' Everything else.
X = X + 2 * R + GAP
FillStyle = vbFSTransparent
Circle (X, Y), R, vbWhite
FillStyle = vbFSSolid
Circle (X, Y), R, vbRed, -PI * 0.25, -PI * 1.75
' Northeast quadrant.
Y = Y + 2 * R + GAP
X = R
FillStyle = vbFSTransparent
Circle (X, Y), R, vbWhite
FillStyle = vbFSSolid
Circle (X, Y), R, vbRed, -0.0000001, -PI * 0.25
' Everything else.
X = X + 2 * R + GAP
FillStyle = vbFSTransparent
Circle (X, Y), R, vbWhite
FillStyle = vbFSSolid
Circle (X, Y), R, vbRed, -PI * 0.25, -0.0000001
End Sub
|