求旋转椭圆的角度

Find the angle of a rotated ellipse

本文关键字:旋转      更新时间:2023-10-16

我正在使用dxflib库开发DXF解析器。我在解析省略号时遇到问题。

当我解析椭圆时,我会收到以下数据:

struct DL_EllipseData 
{
    /*! X Coordinate of center point. */
    double cx;
    /*! Y Coordinate of center point. */
    double cy;
    /*! X coordinate of the endpoint of the major axis. */
    double mx;
    /*! Y coordinate of the endpoint of the major axis. */
    double my;
    /*! Ratio of minor axis to major axis. */
    double ratio;
};

我正试图用下面的方程式来计算这个角度:

auto angle = std::atan2(ellipse.my, ellipse.mx);

但它给了我错误的结果(例如,如果角度是16度,它会给我大约74度)。

我应该如何正确计算旋转角度?

您忽略了椭圆的平移,也就是说,中心可能不位于(0,0)。如果是这种情况,你的解决方案是可以的。

要消除平移的影响,只需减去中心的坐标:

auto angle = std::atan2(ellipse.my - ellipse.cy, ellipse.mx - ellipse.cx);