473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

I need a routine

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)

--
Ceers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------
Nov 20 '05 #1
5 1100
Hi,

Imagine we have a square with its centre at the same point that is the
centre of the circle. Given that, we should analyze only points inside that
bounding square - no point outside the square can belong to the circle.

So we can write an outer and an inner loops iterating on points within the
square. Now, we have to determine whether a point belongs to the circle
itself. Well, this is simple math - as far as I remember, Sqr(dX * dX + dY *
dY) should be less or equal to the circle radius, R (you can actually
compare dX * dX + dY * dY <= R * R to avoid taking the square root), where
dX and dY is the X and Y components of the distance of the point being
analyzed from the centre of the circle.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Crirus" <Cr****@datagroup.ro> wrote in message
news:ed**************@TK2MSFTNGP09.phx.gbl...
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)

--
Ceers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------


Nov 20 '05 #2
"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

Nov 20 '05 #3
You'll need the centre of the circle.

Find the distance from the centre of the circle to the current point. If
that distance is less (or equal to) the radius it is contained in the
circle.

Forget the square... I assume that's there to try and save some processing
filtering the data probably uses about the same amount of resources as
simply checking the distance - especially if compare the square of the
distance to the square of the radius.

Steve


"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote
in message news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi,

Imagine we have a square with its centre at the same point that is the
centre of the circle. Given that, we should analyze only points inside that bounding square - no point outside the square can belong to the circle.

So we can write an outer and an inner loops iterating on points within the
square. Now, we have to determine whether a point belongs to the circle
itself. Well, this is simple math - as far as I remember, Sqr(dX * dX + dY * dY) should be less or equal to the circle radius, R (you can actually
compare dX * dX + dY * dY <= R * R to avoid taking the square root), where
dX and dY is the X and Y components of the distance of the point being
analyzed from the centre of the circle.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Crirus" <Cr****@datagroup.ro> wrote in message
news:ed**************@TK2MSFTNGP09.phx.gbl...
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)

--
Ceers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

Nov 20 '05 #4
Steven,

I would agree if the original poster wouldn't have to *iterate* on *all* the
points within the circle - not just determine whether a single point belongs
to the circle.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Steven Garlinge" <sg*******@iprimus.com.au> wrote in message
news:3f**********@news.iprimus.com.au...
You'll need the centre of the circle.

Find the distance from the centre of the circle to the current point. If
that distance is less (or equal to) the radius it is contained in the
circle.

Forget the square... I assume that's there to try and save some processing
filtering the data probably uses about the same amount of resources as
simply checking the distance - especially if compare the square of the
distance to the square of the radius.

Steve


"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote
in message news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi,

Imagine we have a square with its centre at the same point that is the
centre of the circle. Given that, we should analyze only points inside that
bounding square - no point outside the square can belong to the circle.

So we can write an outer and an inner loops iterating on points within the
square. Now, we have to determine whether a point belongs to the circle
itself. Well, this is simple math - as far as I remember, Sqr(dX * dX + dY *
dY) should be less or equal to the circle radius, R (you can actually
compare dX * dX + dY * dY <= R * R to avoid taking the square root),

where dX and dY is the X and Y components of the distance of the point being
analyzed from the centre of the circle.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Crirus" <Cr****@datagroup.ro> wrote in message
news:ed**************@TK2MSFTNGP09.phx.gbl...
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)

--
Ceers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------



Nov 20 '05 #5
You're right Dimitry
I run through all points...anyway I solved the issue..

thanks

--
Ceers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote
in message news:ut**************@TK2MSFTNGP10.phx.gbl...
Steven,

I would agree if the original poster wouldn't have to *iterate* on *all* the points within the circle - not just determine whether a single point belongs to the circle.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Steven Garlinge" <sg*******@iprimus.com.au> wrote in message
news:3f**********@news.iprimus.com.au...
You'll need the centre of the circle.

Find the distance from the centre of the circle to the current point. If
that distance is less (or equal to) the radius it is contained in the
circle.

Forget the square... I assume that's there to try and save some processing
filtering the data probably uses about the same amount of resources as
simply checking the distance - especially if compare the square of the
distance to the square of the radius.

Steve


"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi,

Imagine we have a square with its centre at the same point that is the
centre of the circle. Given that, we should analyze only points inside that
bounding square - no point outside the square can belong to the circle.
So we can write an outer and an inner loops iterating on points within

the square. Now, we have to determine whether a point belongs to the circle itself. Well, this is simple math - as far as I remember, Sqr(dX * dX
+ dY
*
dY) should be less or equal to the circle radius, R (you can actually
compare dX * dX + dY * dY <= R * R to avoid taking the square root),

where dX and dY is the X and Y components of the distance of the point being
analyzed from the centre of the circle.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Crirus" <Cr****@datagroup.ro> wrote in message
news:ed**************@TK2MSFTNGP09.phx.gbl...
> 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)
>
> --
> Ceers,
> Crirus
>
> ------------------------------
> If work were a good thing, the boss would take it all from you
>
> ------------------------------
>
>


Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: sinisam | last post by:
Object oriented programming is not a new term to me, but when I tried to do some of it... uhh... it sure looked (and felt) like Hell :) I won't bother about things like "help me learn it" (but...
16
by: JustSomeGuy | last post by:
I have a routine that evaluates a polynomial equation that have 3 variables x,y,z of orders 1,2,3 the coefficients of the polynomial are in an array. This routine is quite slow and I'd like to...
4
by: techme | last post by:
I am surprised at how little info there is on this topic. We converted to DB2 v8.1.1.72 painlessly a few months ago. For specific reasons, we stayed on 32-bit. Our OS is AIX 5.2 and our hardward...
2
by: Susan Bricker | last post by:
Greetings Experts ... I have a routine that is invoked when a command button is clicked. The button is located in a form that is tied to a table of Project records. Each Project Record has 0 to...
10
by: HK | last post by:
With VB.NET 2005, and a Windows Form, running on a dual CPU box, I need to take a recordset (e.g. 100,000 records) and spawn a thread to handle an internet XML transaction routine for each of the...
1
by: everymn | last post by:
Hi, Supposedly the Alter Routine privilege can be granted at the level of a single routine but I haven't been able to get that to work. I've tried it a number of different ways like: GRANT...
11
by: Alan Mailer | last post by:
A project I'm working on is going to use VB6 as a front end. The back end is going to be pre-existing MS Access 2002 database tables which already have records in them *but do not have any...
5
by: Railgunner | last post by:
I am looking for a routine that can evaluate boolean expressions like: IF/ELSE-IF (X1=X2 AND (Y=1 OR Z1=Z2)) IF/ELSE-IF (A$='Y' AND B=1) OR (C=1 AND D>E) etc. I can handle...
6
by: Steven W. Orr | last post by:
Given the following code: (I hope it's as simple as possible) :-) #! /usr/bin/python import new class BASE: def __init__( self ): print 'Hello from BASE init' def m1( self ): print 'M1 Base:...
3
by: SpreadTooThin | last post by:
I have a C routine that wants to call a method of its user. In this case the method is a method inside a class. The C routine is passed a void * which can be used by the user any way they like. I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.