c# - 两个圆的切线

标签 c# graphics directx xna geometry

我正在尝试编写一些代码来绘制两条圆之间的切线。到目前为止,我已经能够绘制多个圆圈和圆心之间的线。
我有一个类存储用于绘制圆(半径、位置)的值。 我需要的是此类中的一种方法,用于查找 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;
}

最佳答案

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

编辑:The article on this page看起来很有前途。

关于c# - 两个圆的切线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2458032/

相关文章:

c# - Xamarin-ios 共享和接收音频文件

c# - 使用 SQL Server 管理对象将存储过程从一个 SQL Server 2008 复制到另一个 SQL Server 2008

apache-flex - Flash 绘图 API 中的边框线是绘制在形状内部还是外部?

r - R pch 中的图例未填充

r - 如何在 text(x,y,expression(...)) 中使用多个等号

c++ - 运行我的程序时 Directx 11 蓝屏死机

c# - 如何使图元在 DirectX (2D) 中正确覆盖 Sprite

c++ - 将我的 C++ 演示放到 iPhone 上有多容易?

c# - 用于将 PDF 转换为 HTML 的开源库/工具?

c# - 在 WPF 应用程序的线程 (TASK) 中写入文本框