2010-12-16 106 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