"Crirus" <Cr****@datagroup.ro> schrieb
I need to write a routine that iterate through all points inside a
circle with a known radius
points are known as pairs (x,y)
The function returns all the points on the circle border. That's sufficient
to get all points within the circle.
Private Function GetCirclePoints(ByVal Radius As Single) As Point()
Const Deg As Double = Math.PI / 180D
Dim y As Integer
Dim Result As Point()
Dim Radius2 As Double = Radius * Radius
ReDim Result(CInt(Radius))
For y = 0 To CInt(Radius)
Result(y) = New Point(CInt(Math.Sqrt(radius2 - y * y)), y)
Next
Return Result
End Function
For example, to draw the circle border:
Dim points As Point()
Dim pt As Point
points = GetCirclePoints(50)
For Each pt In points
e.Graphics.DrawRectangle( _
Pens.Black, pt.X + 100, pt.Y + 100, 1, 1 _
)
Next
To calculate all points between (to fill the circle), use an additional loop
from x=0 to pt.x:
Dim points As Point()
Dim pt As Point
points = GetCirclePoints(50)
For Each pt In points
Dim x As Integer
For x = 0 To pt.X
e.Graphics.DrawRectangle( _
Pens.Black, x + 100, pt.Y + 100, 1, 1 _
)
Next
Next
You only get a pie but you can execute it 4 times and multiply coordinates
by all sign combinations (+/+), (+/-), (-/+), (-/-)
--
Armin
http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html