|
根据“圆心角”弧度(函数会将圆心角转成离心角),获取斜椭圆上的点坐标。ptCenter,椭圆中心;a椭圆长轴长度;b,椭圆短轴长度;radian,点于椭圆长轴夹角的弧度;dChangZhouAngle,长轴弧度
CDoublePoint2d GetPointOnEllipse(const CDoublePoint2d& ptCenter, double a, double b, double radian, double dChangZhouAngle)
{
const double dLiXin = atan2(a*sin(radian), b*cos(radian));//离心角
double x = a*cos(dLiXin)*cos(dChangZhouAngle) - b*sin(dLiXin)*sin(dChangZhouAngle) + ptCenter.x;
double y = a*cos(dLiXin)*sin(dChangZhouAngle) + b*sin(dLiXin)*cos(dChangZhouAngle) + ptCenter.y;
return CDoublePoint2d(x, y);
}
问题:
一,为什么不用atan?
答:atan的范围是[-π/2,π/2],atan2的范围是(-π,π]。前者只能表示两个象限,后者可以表示4个。
二,为什么不atan2(a*tan(radian),b)?
答:这样写,和用atan的效果一样。
|
|