Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to join overlapping circles?

Tags:

I want to visually join two circles that are overlapping so that

AltText

becomes

alt text

I already have methods for partial circles, but now I need to know how large the overlapping angle for earch circle is, and I don't know how to do that.

Anyone got an Idea?

like image 322
Cobra_Fast Avatar asked Dec 16 '10 18:12

Cobra_Fast


People also ask

How do I merge circles in Autocad?

With the 'Merge Polylines & Circles' command you can merge them effectively joining the two areas they outline.


2 Answers

Phi= ArcTan[ Sqrt[4 * R^2 - d^2] /d ] 

HTH!

Edit

For two different radii:

Simplifying a little:

Phi= ArcTan[Sqrt[-d^4 -(R1^2 - R2^2)^2 + 2*d^2*(R1^2 + R2^2)]/(d^2 +R1^2 -R2^2)] 

Edit

If you want the angle viewed from the other circle center, just exchange R1 by R2 in the last equation.

Here is a sample implementation in Mathematica:

f[center1_, d_, R1_, R2_] := Module[{Phi, Theta},     Phi=  ArcTan[Sqrt[-d^4-(R1^2-R2^2)^2 + 2*d^2*(R1^2 + R2^2)]/(d^2 +R1^2 -R2^2)]     Theta=ArcTan[Sqrt[-d^4-(R1^2-R2^2)^2 + 2*d^2*(R1^2 + R2^2)]/(d^2 -R1^2 +R2^2)]     {Circle[{center1, 0}, R1, {2 Pi - Phi,   Phi}],      Circle[{d,       0}, R2, {Pi - Theta,  -Pi + Theta}]}     ]; Graphics[f[0, 1.5, 1, 1]] 

alt text

Graphics[f[0, 1.5, 1, 3/4]]   

alt text

And...

ImageMultiply[  Binarize@FillingTransform[#],   ImageResize[Import@  "http://i305.photobucket.com/albums/nn235/greeneyedgirlox/blondebabybunny.jpg",     ImageDimensions@#]] &@  Rasterize@Graphics[f[0, 1.5, 1, 1], Background -> Black] 

alt text

:)

like image 52
Dr. belisarius Avatar answered Oct 19 '22 01:10

Dr. belisarius


Now this will work 100% for you even the figure is ellipse and any number of figures

    private void Form1_Paint(object sender, PaintEventArgs e)     {         Pen p = new Pen(Color.Red, 2);                Rectangle Fig1 = new Rectangle(50, 50, 100, 50);  //dimensions of Fig1         Rectangle Fig2 = new Rectangle(100, 50, 100, 50); //dimensions of Fig2         . . .          DrawFigure(e.Graphics, p, Fig1);            DrawFigure(e.Graphics, p, Fig2);         . . .          //remember to call  FillFigure after  drawing all figures.         FillFigure(e.Graphics, p, Fig1);          FillFigure(e.Graphics, p, Fig2);         . . .     }     private void DrawFigure(Graphics g, Pen p, Rectangle r)     {         g.DrawEllipse(p, r.X, r.Y, r.Width, r.Height);     }     private void FillFigure(Graphics g, Pen p, Rectangle r)     {         g.FillEllipse(new SolidBrush(this.BackColor), r.X + p.Width, r.Y + p.Width, r.Width - 2 * +p.Width, r.Height - 2 * +p.Width);      //Adjusting Color so that it will leave border and fill      } 

alt text

like image 22
Javed Akram Avatar answered Oct 19 '22 01:10

Javed Akram