2010-12-16 108 views
21

我想在視覺上加入兩個圓即是重疊的,這樣如何加入重疊圓圈?

AltText

成爲

alt text

我已經有部分圓的方法,但現在我需要知道如何大搜索圈的重疊角度是,我不知道該怎麼做。

任何人都有想法?

+0

嗯好一個!如果你知道它們的中心和半徑,你可以找到圓的交點。從那裏,你應該能夠找出重疊的部分 - 由交點創建的每個圓上的兩個部分中的較小部分...有幫助嗎?我從來沒有嘗試編碼,但我可以嘗試一些僞代碼...... – FrustratedWithFormsDesigner 2010-12-16 18:10:01

+0

圈子有相同的半徑嗎? – Ishtar 2010-12-16 18:11:33

+0

這些圈子偶爾會有相同的輻射,但通常它們不會。 – 2010-12-16 18:13:27

回答

36

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

HTH!

編輯

對於兩個不同的半徑:

簡化了一點:

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

編輯

如果您想從另一個圓心看到角度,只需在最後一個等式中將R2與R2交換即可。

這裏是數學的實現:

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

而且......

ImageMultiply[ 
[email protected][#], 
ImageResize[[email protected] 
"http://i305.photobucket.com/albums/nn235/greeneyedgirlox/blondebabybunny.jpg", 
    [email protected]#]] &@ 
[email protected][f[0, 1.5, 1, 1], Background -> Black] 

alt text

:)

+2

這兩個半徑不一定相同。 – 2010-12-16 18:32:15

+0

@Ignacio請參閱編輯 – 2010-12-16 18:40:31

+0

D是什麼?我如何得到D?爲什麼它在編輯的某處浮動? – 2010-12-16 19:46:19

5

現在沒有時間解決它。不過,我會給你你所需要的工作了:

http://en.wikipedia.org/wiki/Triangle#The_sine.2C_cosine_and_tangent_rules

在圖片上看到的三角形A,B,C維基百科。設A是左圓的中心,B是右圓的中心。 AC是左圓的半徑,BC是右圓的半徑。

alt text

然後點C將是頂交點。 A,α中的拐角是左側圓角的一半。b,β中的拐角,右側圓角的一半。這些是你需要的角度,對吧?

維基百科進一步解釋說:「如果知道任何三角形的所有三邊的長度,就可以計算出三個角度。

僞代碼:

a=radius_a 
b=radius_b 
c=b_x - a_x 
alpha=arccos((b^2 + c^2 - a^2)/(2*b*c)) //from wikipedia 
left_angle=2*alpha 

祝你好運:)

8

現在,這個工作將100%爲你甚至圖是橢圓任意數量的數字

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

+6

謝謝您不要仔細閱讀問題和意見。我正在使用OpenGL,而不是.net繪圖。 – 2010-12-19 14:55:47