5

我有一个中心点在原点的椭圆(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# 给出上述值?

4

1 回答 1

17

http://www.mathopenref.com/coordparamellipse.html

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

x(t) = a cos t,
y(t) = b sin t

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

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 指出的那样,如果您希望计算与通过中心且角度为 theta 的线的精确交点,它会变得有点复杂,因为我们需要找到对应于 theta 的点:

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 度之间的 theta,添加 π:

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

对于 -180 到 -90 度之间的 theta,减去 π:

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 * π

于 2013-07-20T12:14:00.963 回答