MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: how to get the area of circles

  • To: mathgroup at smc.vnet.net
  • Subject: [mg74779] Re: [mg74751] how to get the area of circles
  • From: Darren Glosemeyer <darreng at wolfram.com>
  • Date: Thu, 5 Apr 2007 04:06:40 -0400 (EDT)
  • References: <200704040753.DAA11559@smc.vnet.net>

doufunao wrote:
> hi guys,
>
> I'm working on a project. I need to calculate the area of many circles
> in a 2D space which may overlap each other.
> It's quite complicated. I am not sure whether mathematica can do this.
> Is there any software/lib/package available already?
> thanks.
>
>   

One possibility is to define an indicator function which is 1 for a 
point that is inside of any of the circles and 0 otherwise and then 
integrate over a region that contains all of the circles. The value of 
the integral will be the area. This can be accomplished using Boole, 
which is 1 when it's argument is True and 0 when it's argument is False, 
and NIntegrate.  Here is an example.

First, we define a function randomCircle that will give the inequality 
for a circle of some random radius centered at some random point. The 
arguments define the ranges for the random values.

In[1]:= randomCircle[xrange_, yrange_, rrange_] := (x - Random[Real, 
xrange])^2 + (y - Random[Real, yrange])^2 <=
             Random[Real, rrange]


Here is an example circle with center coordinates and radius value all 
between 1 and 3.

In[2]:= randomCircle[{1, 3}, {1, 3}, {1, 3}] // InputForm

Out[2]//InputForm=
(-2.0661317251902482 + x)^2 + (-1.6104274337228972 + y)^2 <= 
1.4140906260268187


The following will give a list of circle inequalities with center 
coordinates and radius between 0 and 5.

In[3]:= fivecircles = Table[randomCircle[{0, 5}, {0, 5}, {0, 5}], {5}];


By applying Or to the list fivecircles, we have the condition for being 
in at least one of the circles. The indicator function will then be 
Boole of that expression.

In[4]:= InputForm[indicator = Boole[Apply[Or, fivecircles]]]

Out[4]//InputForm=
Boole[(-3.3731865816952618 + x)^2 + (-4.955490782699668 + y)^2 <= 
3.8131091026269477 ||
  (-1.8516457967846403 + x)^2 + (-0.38266240446865113 + y)^2 <= 
0.42049688102669647 ||
  (-2.082030985785312 + x)^2 + (-1.5497542909564879 + y)^2 <= 
4.623641160034157 ||
  (-3.140716303429742 + x)^2 + (-1.1690455292870399 + y)^2 <= 
1.3477273176024342 ||
  (-4.139078714591639 + x)^2 + (-0.6079159508633709 + y)^2 <= 
2.1205909039189836]


For these particular circles, integrating from -5 to 10 for both x and y 
will be sufficient to cover the circles.

In[5]:= NIntegrate[indicator, {x, -5, 10}, {y, -5, 10}] // Chop

Out[5]= 30.0377


Darren Glosemeyer
Wolfram Research


  • Prev by Date: Re: Efficient BesselJ and LegendreP Evaluation
  • Next by Date: Re: Finding unknown parameters using Mathematica
  • Previous by thread: Re: how to get the area of circles
  • Next by thread: Re: how to get the area of circles