4.75

4.8 | 9 ratings Rate this file 48 downloads (last 30 days) File Size: 3.51 KB File ID: #15899

Analytical intersection area between two circles

by Guillaume JACQUENOT

 

10 Aug 2007 (Updated 14 Aug 2007)

Code covered by BSD License  

Compute the intersection area between 2 circles. The function allows to evaluate the intersection ar

Download Now | Watch this File

File Information
Description

Compute the overlap area between 2 circles defined in an array Computation is vectorized, and intersection area are computed an analytical way.
  
Input: Circles data presented in an array G of three columns.
       G contains parameters of the n circles
          . G(1:n,1) - x-coordinate of the center of circles,
          . G(1:n,2) - y-coordinate of the center of circles,
          . G(1:n,3) - radii of the circles
       Each row of the array contains the information for one circle.

       Input can also be provided in three different vectors. These vectors can be row or column vectors. The 1st one corresponds to x-coordinate of the center of circles, the 2nd one to the y-cooridnate and the 3rd one to the radii of the circles.

Output: Square matrix M(n,n) containing intersection areas between circles
        M(i,j) contains the intersection area between circles i & j
        By definition, M(i,i) corresponds to the area of circle i.

MATLAB release MATLAB 7 (R14)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (9)
10 Aug 2007 John D'Errico

This is ok. It could be better. What could the author have done to improve it?

Think about the person using this code. What are the arguments? When you do help for the code, all it says about the input(s) is they can be in the form of an nx3 array, or as 3 vectors. WHAT ARE THE VECTORS? WHAT DO THEY MEAN? WHAT ORDER ARE THEY EXPECTED TO LIE IN? Give your user a hint. Is one of them the radius? Maybe its the square of the radius? Which one? While it might be obvious to the author, it is not at all so from the help.
 
The computation itself seems to be an efficient one, fairly carefully vectorized. although beware of trying to run this with several thousands of circles. You should expect memory problems.

I'd have liked to see more error checking. For example, one might check that the radii are all non-negative. This might catch some cases where the user has entered the vectors in the wrong sequence.

I also note that mlint flagged 8 lines. Minor points all, but worthwhile dealing with them.

Next, since the matrix of area intersections is symmetric, the author might have computed only an upper or lower triangle to save some time, then symmetrized it. The diagonal is trivial of course. I don't know if this would be a gain or not.

Finally, this is one of those codes where you as an author can expect to see people asking for an explanation of how it works. Yes, an assiduous reader can work it out from the code and the internal comments, but it might be worthwhile to include that explanation, rather than just the blanket statement that the area is computed analytically.

I'll be happy to upgrade my rating if improvements are made to this code.

13 Aug 2007 Pierre Launay

Efficient, quick, neat

13 Aug 2007 John D'Errico

Nicely cleaned up. My thanks to the author.

14 Aug 2007 Benjamin Le Blan

Great! Thanks!

08 May 2008 walid osamy  
18 Nov 2008 M. A. Hopcroft

Works great, help file is good. Thanks!

29 Apr 2009 Idillus  
16 Jun 2009 Osama

very handy. thanks a lot !!

16 Jun 2009 John D'Errico

Hmm. I just noticed that my followup rating was shadowed out, and the original one remains. I'll see if I can't have the old rating removed.

Please login to add a comment or rating.
Updates
13 Aug 2007

Some comments were added to ease the use of the function. Precise description of the user inputs is described.
Some argument verifications are also performed.
Finally, the number of calculations has been divided by two.

Thanks John D'Errico!

13 Aug 2007

Some explanations, comments were added. Input arguments are detailed.
Verifications of input arguments are performed.
The number of calculations has been divided by two.

Thanks John D'Errico

14 Aug 2007

A mistake was identified with boundary conditions. I did not take into account the fact that one can wanted to compute the overlap area between two identical circles. Thanks Eric Le Page

Tag Activity for this File
Tag Applied By Date/Time
circle Guillaume JACQUENOT 22 Oct 2008 09:22:46
intersection Guillaume JACQUENOT 22 Oct 2008 09:22:46
area Guillaume JACQUENOT 22 Oct 2008 09:22:46
analytical Guillaume JACQUENOT 22 Oct 2008 09:22:46
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com