C
Crirus
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)
with a known radius
points are known as pairs (x,y)
Crirus said: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)
Dmitriy Lapshin said: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 said: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)
Steven Garlinge said: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
dYDmitriy Lapshin said: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) 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 said: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)
Dmitriy Lapshin said: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 said: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
in message news:%[email protected]...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
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)