File Exchange

image thumbnail

Analytical intersection area between two circles

version 1.0 (3.51 KB) by

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

16 Ratings



View License

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.

Comments and Ratings (16)

balamonica k

Jaume Miro

Good work, it's a useful and easy to understand code, thanks!

amal Mbarki

great work! but if i would like to calculate the intersection area of two ellipse in the same way,how the analytical equation became??


Davide (view profile)

Good job! But, maybe a possibility to have ellipses and not circles will be helpful and really nice!

Weiguang Ding

John D'Errico

John D'Errico (view profile)

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.


Osama (view profile)

very handy. thanks a lot !!


M. A. Hopcroft

M. A. Hopcroft (view profile)

Works great, help file is good. Thanks!

walid osamy

Benjamin Le Blan

Great! Thanks!

John D'Errico

Nicely cleaned up. My thanks to the author.

Pierre Launay

Efficient, quick, neat

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.


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

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!

MATLAB Release
MATLAB 7 (R14)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today