如何在给定角度的情况下找到椭圆上的点

本文关键字:情况下 | 更新日期: 2023-09-27 18:24:14

我有一个椭圆,中心点在原点(0,0)

double dHalfwidthEllipse = 10; 
double dHalfheightEllipse = 20;
double dAngle = 30;//Its in degree
PointF ptfPoint = new PointF();//To be found
PointF ptfOrigin = new PointF(0, 0);//Origin

点相对于原点的角度=30度;现在如何使用C#在给定上述值的情况下获得该点?

如何在给定角度的情况下找到椭圆上的点

请参阅http://www.mathopenref.com/coordparamellipse.html

中心点在原点、半宽a和半高b的椭圆的参数方程是

x(t)=cos t,
y(t)=b sint

如果你只是想画一个椭圆,给定

double dHalfwidthEllipse = 10;       // a
double dHalfheightEllipse = 20;      // b
PointF ptfOrigin = new PointF(0, 0); // Origin

你只需要

PointF ptfPoint = 
    new PointF(ptfOrigin.X + dHalfwidthEllipse * Math.Cos(t * Math.Pi/180.0), 
               ptfOrigin.Y + dHalfheightEllipse * Math.Sin(t * Math.Pi/180.0) );

其中t在-180度和180度之间变化。

然而,正如@Sebastian所指出的,如果你想计算一条通过θ角中心的线的精确交点,它会变得有点复杂,因为我们需要找到一个对应于θ的t:

y(t)/x(t)=tanθ

b sin t/(a cos t)=tanθ

b/a tan t=tanθ

t=arctan(a tanθ/b)+n*π

所以如果我们添加

double dAngle = 30;                  // theta, between -90 and 90 degrees

我们可以计算t和ptfPoint:

double t = Math.Atan( dHalfwidthEllipse * Math.Tan( dAngle * Math.Pi/180.0 ) 
                                                    / dHalfheightEllipse);
PointF ptfPoint = 
    new PointF(ptfOrigin.X + dHalfwidthEllipse * Math.Cos(t), 
               ptfOrigin.Y + dHalfheightEllipse * Math.Sin(t) );

这适用于正x轴周围的区域。对于介于90度和180度之间的θ,添加π:

double t = Math.Atan( dHalfwidthEllipse * Math.Tan( dAngle * Math.Pi/180.0 ) 
                                                    / dHalfheightEllipse) + Math.Pi;

对于介于-180和-90度之间的θ,减去π:

double t = Math.Atan( dHalfwidthEllipse * Math.Tan( dAngle * Math.Pi/180.0 ) 
                                                    / dHalfheightEllipse) - Math.Pi;

当你接近y轴时,x(t)接近零,上面的计算除以零,但你可以使用相反的方法:

x(t)/y(t)=tan(90-θ)

a cos t/(b sin t)=tan(90-θ)

a/b tan t=tan(90-θ)

t=arctan(b-tan(90-θ)/a)+n*π