旋转中心的计算方式

1、三点计算旋转中心

        /// <summary>
        /// <para>二维:已知圆上三点,求圆心坐标</para>
        /// <para>三个点不在同一直线上</para>
        /// </summary>
        /// <param name="P1">点1</param>
        /// <param name="P2">点2</param>
        /// <param name="P3">点3</param>
        /// <returns></returns>
        public PointF GetCentre(PointF P1,PointF P2, PointF P3)
        {
            double a13 = P1.X - P3.X;
            double a13_ = P1.X + P3.X;
            double b13 = P1.Y - P3.Y;
            double b13_ = P1.Y + P3.Y;
            double a12 = P1.X - P2.X;
            double a12_ = P1.X + P2.X;
            double b12 = P1.Y - P2.Y;
            double b12_ = P1.Y + P2.Y;
 
            double a12b12_2 = a12 * a12_ + b12 * b12_;
            double a13b13_2 = a13 * a13_ + b13 * b13_;
 
            double a13b12 =2* a13 * b12;
            double a12b13 =2* a12 * b13;
 
 
            if (a12b13 - a13b12 == 0) return new PointF((P2.X+P1.X)/2, (P2.Y+P1.Y)/2);
            double af = a12b13 - a13b12;
            double bf = a13b12 - a12b13;
            double az = b13 * a12b12_2 - b12 * a13b13_2;
            double bz = a13 * a12b12_2 - a12 * a13b13_2;
            double a = az / af;
            double b = bz / bf;
            return new PointF((float)a,(float)b);
        }

2、两点加旋转角度计算旋转中心

/// <summary>
        
        /// </summary>
        /// <param name="p1">旋转前</param>
        /// <param name="p2">旋转后</param>
        /// <param name="angle">逆时针角度</param>
        /// <returns></returns>
        public static PointF GetRotateCenter(PointF P1,PointF P2, double angle)
        {

         PointF point=new PointF();
            try
            {
             
                double a = (angle / 180) * Math.PI;
 
               
                double d = Math.Pow(Math.Pow(P2.X- P1.X, 2) + Math.Pow(P2.Y- P1.Y, 2), 0.5);
                double r = (d / 2) / Math.Sin(a / 2);
                double xt = (1 - r / d) * P1.X + (r / d) * P2.X;
                double yt = (1 - r / d) * P1.Y + (r / d) * P2.Y;
                double b = ((90.0 / 180) * Math.PI) - (a / 2);
                double x0 = Math.Cos(b) * (xt - P1.X) - Math.Sin(b) * (yt - P1.Y) + x1;
                double y0 = Math.Cos(b) * (yt - P1.Y) + Math.Sin(b) * (xt - P1.X) + y1;
 
               point.X=(float)x0;

                point.Y=(float)y0;
            }
            catch (Exception)
            {
               

                 point.X=-1;

                point.Y=-1;

            }

        return point
        }

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值