【问题标题】:tangent of two circles两个圆的切线
【发布时间】:2010-03-16 20:50:15
【问题描述】:

我正在尝试编写一些代码来绘制两条圆之间的切线。到目前为止,我已经能够在中心之间绘制多个圆圈和线条。
我有一个类,它存储用于绘制圆的值(半径、位置)。 我需要的是此类中的一种方法来查找 2 个圆之间的所有可能切线。
任何帮助都会很棒。
这就是我目前所拥有的(很可能是一堆垃圾)

public static Vector2[] Tangents(circle c1, circle c2)
{
            if (c2.radius > c1.radius)
            {
                circle temp = c1;
                c1 = c2;
                c2 = temp;
            }
            circle c0 = new circle(c1.radius - c2.radius, c1.center);
            Vector2[] tans = new Vector2[2];
            Vector2 dir = _point - _center;
            float len = (float)Math.Sqrt((dir.X * dir.X) + (dir.Y * dir.Y));
            float angle = (float)Math.Atan2(dir.X, dir.Y);
            float tan_length = (float)Math.Sqrt((len * len) - (_radius * _radius));
            float tan_angle = (float)Math.Asin(_radius / len);
            tans[0] = new Vector2((float)Math.Cos(angle + tan_angle), (float)Math.Sin(angle + tan_angle));
            tans[1] = new Vector2((float)Math.Cos(angle - tan_angle), (float)Math.Sin(angle - tan_angle));
            Vector2 dir0 = c0.center - tans[0];
            Vector2 dir1 = c0.center - tans[1];

            Vector2 tan00 = Vector2.Add(Vector2.Multiply(tans[0], (float)c2.radius), c1.center);
            Vector2 tan01 = c2.center;
            Vector2 tan10 = Vector2.Add(Vector2.Multiply(tans[1], (float)c2.radius), c1.center);
            Vector2 tan11 = c2.center;
}

【问题讨论】:

    标签: c# graphics directx xna geometry


    【解决方案1】:

    恕我直言,在开始编码之前,您应该先尝试用铅笔和纸解决问题。这个链接at Mathworld 似乎是一个很好的起点。

    编辑:The article on this page 看起来很有希望。

    【讨论】:

      猜你喜欢
      • 2012-08-15
      • 2023-01-19
      • 2020-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多