坐标角度旋转(加班三天整出来的可用的角度旋转)

        /// <summary>
        /// 获取两个点的距离
        /// </summary>
        /// <param name="sPoint"></param>
        /// <param name="ePoint"></param>
        /// <returns></returns>
        private static double GetLengthWithAngle(DfPoint sPoint, DfPoint ePoint)
        {
            var angle = CalculateAngle(sPoint, ePoint);

            var deltaX = ePoint.X - sPoint.X;
            var deltaY = ePoint.Y - sPoint.Y;
            double deltaAngle = angle * Math.PI / 180;
            double rotatedX = deltaX * Math.Cos(deltaAngle) - deltaY * Math.Sin(deltaAngle);
            double rotatedY = deltaX * Math.Sin(deltaAngle) + deltaY * Math.Cos(deltaAngle);
            double length = Math.Sqrt(rotatedX * rotatedX + rotatedY * rotatedY);
            return length;
        }
        ///按角度旋转坐标点
        private static DfPoint RotatePoint(DfPoint source, DfPoint o, double angle)
        {
            double rotatedX = 0, rotatedY = 0;
            double radian = angle * Math.PI / 180;
            rotatedX = o.X + (source.X - o.X) * Math.Cos(radian) - (source.Y - o.Y) * Math.Sin(radian);
            rotatedY = o.Y + (source.X - o.X) * Math.Sin(radian) + (source.Y - o.Y) * Math.Cos(radian);
            return new DfPoint(rotatedX, rotatedY);
        }
        /// 计算两个点的角度
        private static double CalculateAngle(DfPoint start, DfPoint end)
        {
            // 计算水平和垂直方向上的差值
            double dx = start.X - end.X;
            double dy = start.Y - end.Y;

            // 使用反正切函数计算角度(以弧度为单位)
            double radians = Math.Atan2(dy, dx);

            // 将弧度转换为角度
            double angle = radians * (180 / Math.PI);

            // 将负角度调整到正角度范围内(0-360度)
            //if (angle < 0)
            //{
            //    angle += 360;
            //}
            return angle;
        }

对于三角函数好的朋友,这都不是事儿,像笔者这种不好的,就很需要时间去调整了。

地质图形绘制中,会使用到的,按角度绘制坐标点。

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容