# [Numpy-discussion] floating point arithmetic issue

Benjamin Root ben.root@ou....
Fri Jul 30 12:16:17 CDT 2010

```2010/7/30 Guillaume Chérel <guillaume.c.cherel@gmail.com>

> On Fri, Jul 30, 2010 at 6:15 PM, Christopher Barker
> <Chris.Barker@noaa.gov> wrote:
> > Guillaume Chérel wrote:
> >> As for the details about my problem, I'm trying to compute the total
> >> surface of overlapping disks. I approximate the surface with a grid and
> >> count how many points of the grid fall into at least one disk.
> >
> > That is a highly approximate way to do it - which may be fine, but  I
> > doubt any floating point errors you get are going to make it worse.
> >
>
> It is a problem in my algorithm because it modifies the number of
> points that are considered inside a given disk (namely, the points
> that are at the very boundary of the disk), and results in something
> like an "index out of bounds" error later.
>
> >  > if you
> >> know of another good way to compute the surface of overlapping disks,
> >> I'd be glad to know.
> >
> > Are these "disks" exactly round? If so -- use coordinate geometry to
> > calculate it exactly (or as exactly as floating point allows ;-) )
> >
> > I just googled: "area of intersecting circles"
> >
> > And got a bunch of hits.
>
> Originally, I was looking to solve my problem quickly, and a rough
> approximation was (and is) enough. There are indeed solutions for
> computing the area of 2 intersecting disks, but my problem may involve
> many more than 2 disks at a time, which makes things a lot more
> complicated (to me, at least).
>

Supposing that you know the centers and radius of each disk, one could
brute-force a calculation of the distance of each point you are sampling to
the center of each disk and see if the distances are within the radius of
the particular disk.

To make it a little more efficient, you can use SciPy's kdtrees and build
two trees, one for the points you wish to sample, and another containing the
centers of each disk and use that to find the closest points to each center.

Ben Root
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20100730/7d0ebc41/attachment.html
```