C# 求圆弧和圆弧的交点坐标算法

在求圆弧和圆弧的交点坐标的时候,我们同样和我上一个求直线和圆弧交点坐标一样,先来分析一下,主要分为
第一步: 求圆弧和圆弧交点,我们可以先求该圆弧对应的圆和圆的交点。
第二步:通过判断交点是否同时是存在两个圆弧上,注意交点必须同时存在于两个圆弧上,这个交点才是真正的交点(这个地方有点小坑,希望能自己画图理解)。

下面开始展示代码,伸手党有福了,可能有些地方写的不好,望谅解,创作不易,喜欢给个好评吧。

主干

   /// <summary>
        /// 计算圆弧和圆弧的交点方法
        /// </summary>
        /// <param name="arc">第一个圆</param>
        /// <param name="arcTwo">第二个圆</param>
        /// <param name="ht">用于存放交点,和error信息</param>
        /// <returns>返回交点和error信息</returns>
        internal static Hashtable ArcIntersectArc(Arc arc, Arc arcTwo, Hashtable ht)
        {
   
            //得到弧心坐标
            Vector2 vector = arc.center;
            Vector2 vectorTwo = arcTwo.center;
            //起始角度
            double startAngle = arc.startAngle;
            double startAngleTwo = arcTwo.startAngle;
            //终止角度
            double endAngle = arc.endAngle;
            double endAngleTwo = arcTwo.endAngle;
            //得到半径
            double rad = arc.radius;
            double radTwo = arcTwo.radius;
            //圆弧的顺逆
            bool _direction = arc.direction;
            bool _directionTwo = arcTwo.direction;
            Vector2[] points = new Vector2[2];
            CircleInsect(arc, arcTwo, points);
            //用于判断是否有交点
            bool judgeNode = false;
            //用于第一次存储交点
            List<Vector2> node = new List<Vector2>();
            //存储的版本号
            int version = 0;
            //用于第二次存储交点
            List<Vector2> nodeTwo = new List<Vector2>();
            if (Zero(points[0]))
            {
   
                if (vector.y == vectorTwo.y)
                {
      //当两个弧心坐标的y坐标相等时,以x坐标小的为中心弧心
                    if (vector.x < vectorTwo.x)
                    {
     //vector 做中心弧心
                        JudgeDotQualified(vector, points[0], startAngle, endAngle, node, _direction);
                        if (node.Count == 1)
                        {
   
                            if (node[0] != null)
                            {
   
                                JudgeDotQualified(vectorTwo, points[0], startAngleTwo, endAngleTwo, nodeTwo, _directionTwo);
                                //表示第一次有一个值
                                version = 1;
                            }
                        }
                    }
                    else
                    {
   
                        //vectorTwo 做中心弧心
                        JudgeDotQualified(vectorTwo, points[0], startAngleTwo, endAngleTwo, node, _directionTwo);
                        if (node.Count == 1)
                        {
   
                            if (node[0] != null)
                            {
   
                                JudgeDotQualified(vector, points[0], startAngle, endAngle, nodeTwo, _direction);
                                //表示第一次有一个值
                                version = 1;
                            }
                        }
                    }
                }
                else if (vector.y < vectorTwo.y)
                {
     //取用弧心坐标的y坐标小的做为中心弧心 vector
                    JudgeDotQualified(vector, points[0], startAngle, endAngle, node, _direction);
                    if (node.Count == 1)
                    {
   
                        if (node[0] != null)
                        {
   
                            JudgeDotQualified(vectorTwo, points[0], startAngleTwo, endAngleTwo, nodeTwo, _directionTwo);
                            //表示第一次有一个值
                            version = 1;
                        }
                    }
                }
                else
                {
     //取用弧心坐标的y坐标小的做为中心弧心vectorTwo
                    JudgeDotQualified(vectorTwo, points[0], startAngleTwo, endAngleTwo, node, _directionTwo);
                    if (node.Count == 1)
                    {
   
                        if (node[0] != null)
                        {
   
                            JudgeDotQualified(vector, points[0], startAngle, endAngle, nodeTwo, _direction)
  • 10
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
C# 中,可以使用 System.Drawing.Drawing2D 命名空间中的 GraphicsPath 类来绘制圆弧。如果已知圆弧的起点和终点坐标以及圆弧的角度,可以通过以下步骤来创建圆弧: 1. 计算圆弧的半径,可以使用数学公式:半径 = 起点到终点的距离 / 2sin(圆弧角度/2)。 2. 计算圆弧的圆心坐标,可以使用数学公式:圆心坐标 = (起点坐标 + 终点坐标) / 2 + (起点坐标 - 终点坐标) * i / 2tan(圆弧角度/2),其中 i 表示虚数单位。 3. 使用 GraphicsPath 类的 AddArc 方法来添加圆弧路径。AddArc 方法需要指定圆弧的外接矩形和起始角度、圆弧角度,可以使用 RectangleF 结构表示外接矩形,使用 GetAngle 方法来计算起始角度。 代码示例: ``` Point startPoint = new Point(10, 10); Point endPoint = new Point(50, 50); float angle = 90; // 圆弧角度 float distance = (float)Math.Sqrt(Math.Pow(endPoint.X - startPoint.X, 2) + Math.Pow(endPoint.Y - startPoint.Y, 2)); float radius = distance / (2 * (float)Math.Sin(angle / 2 * Math.PI / 180)); PointF center = new PointF((startPoint.X + endPoint.X) / 2, (startPoint.Y + endPoint.Y) / 2); float angleRad = (float)Math.Atan2(endPoint.Y - startPoint.Y, endPoint.X - startPoint.X); angleRad += angle / 2 * Math.PI / 180; PointF arcCenter = new PointF(center.X + radius * (float)Math.Cos(angleRad), center.Y + radius * (float)Math.Sin(angleRad)); RectangleF arcRect = new RectangleF(arcCenter.X - radius, arcCenter.Y - radius, radius * 2, radius * 2); float startAngle = (float)Math.Atan2(startPoint.Y - arcCenter.Y, startPoint.X - arcCenter.X) * 180 / Math.PI; float sweepAngle = angle; GraphicsPath path = new GraphicsPath(); path.AddArc(arcRect, startAngle, sweepAngle); ``` 这将创建一个圆心坐标为 (30, 30),半径为 21.21,起点为 (10, 10),终点为 (50, 50),角度为 90 度的圆弧路径。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值