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: [mg74803] Re: how to get the area of circles
  • From: "Valeri Astanoff" <astanoff at gmail.com>
  • Date: Thu, 5 Apr 2007 04:19:00 -0400 (EDT)
  • References: <euvlho$b9n$1@smc.vnet.net>

On 4 avr, 09:53, "doufunao" <gaoshan2... at gmail.com> 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.

Good day,

Here is a solution using "Boole" :

In[1]:=
areaOfCircles[circles_List(*{{a1,b1,r1},{a2,b2,r2}...}*)]:=
Module[{},
ixmin = Ordering[circles,1,#1[[1]] < #2[[1]]&]//First;
xmin = circles[[ixmin,1]]-circles[[ixmin,3]];

ixmax = Ordering[circles,1,#1[[1]] > #2[[1]]&]//First;
xmax = circles[[ixmax,1]]+circles[[ixmax,3]];

iymin = Ordering[circles,1,#1[[2]] < #2[[2]]&]//First;
ymin = circles[[iymin,2]]-circles[[iymin,3]];

iymax = Ordering[circles,1,#1[[2]] > #2[[2]]&]//First;
ymax = circles[[iymax,2]]+circles[[iymax,3]];

insideQ[{x_,y_},{a_,b_,r_}] := (x-a)^2+(y-b)^2 < r^2;
NIntegrate[Boole[Or@@(insideQ[{x,y},#]& /@ circles)],
{x,xmin,xmax},{y,ymin,ymax}]
];

In[2]:=circles={{-.5,1.5,9.7},{-1.8,4.3,5.8},
{3.5,4.0,1.7},{2.1,1.7,3.1},{1.4,5.9,1.9}};

In[3]:=areaOfCircles[circles]//Timing

Out[3]={0.078Second,194.654}


V.Astanoff



  • Prev by Date: Re: Expansion symbolic
  • Next by Date: Re: how to get the area of circles
  • Previous by thread: Re: how to get the area of circles
  • Next by thread: Re: Expansion symbolic