【C#】 根据椭圆边框和任意角度计算椭圆二维坐标

转自:https://blog.csdn.net/chenlu5201314/article/details/99678398

椭圆公式 

椭圆半径公式如下

r = frac{ a cdot b}{sqrt{(a cdot sin{	heta})^2+(b cdot cos{	heta})^2}}

椭圆坐标公式

x = frac{ a cdot bcdot cos 	heta}{sqrt{(a cdot sin{	heta})^2+(b cdot cos{	heta})^2}}

y = frac{ a cdot bcdot sin{	heta} }{sqrt{(a cdot sin{	heta})^2+(b cdot cos{	heta})^2}}

角度转弧度公式

radian =frac{pi cdot angle}{180}

弧度转角度公式

angle =frac{180 cdot radian }{pi}

  • r 为半径
  • a 为横轴(长轴)
  • b 为竖轴(短轴)
  • 	heta 为任意角度/弧度,
  • x 为椭圆上 	heta 对应的横坐标
  • y 为椭圆上 	heta 对应的纵坐标
  • radian 弧度
  • angle 角度

C#代码

        /// <summary>
        /// 椭圆求点公式
        /// </summary>
        /// <param name="lpRect">椭圆边框</param>
        /// <param name="angle">角度</param>
        /// <returns></returns>
        public Point GetArcPoint(Rectangle lpRect, float angle)
        {
            Point pt = new Point();
            double a = lpRect.Width / 2.0f;
            double b = lpRect.Height / 2.0f;
            if (a == 0 || b == 0) return new Point(lpRect.X, lpRect.Y);
 
            //弧度
            double radian = angle * Math.PI / 180.0f;
 
            //获取弧度正弦值
            double yc = Math.Sin(radian);
            //获取弧度余弦值
            double xc = Math.Cos(radian);
            //获取曲率  r = ab/Sqrt((a.Sinθ)^2+(b.Cosθ)^2
            double radio = (a * b) / Math.Sqrt(Math.Pow(yc * a, 2.0) + Math.Pow(xc * b, 2.0));
 
            //计算坐标
            double ax = radio * xc;
            double ay = radio * yc;
            pt.X = (int)(lpRect.X + a + ax);
            pt.Y = (int)(lpRect.Y + b + ay);
            return pt;
        }
原文地址:https://www.cnblogs.com/jiangcm/p/11640663.html