找到旋转椭圆的角度

时间:2015-06-30 09:20:18

标签: c++ rotation angle ellipse dxf

我正在使用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度)。

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

1 个答案:

答案 0 :(得分:4)

您忽略椭圆的平移,即中心可能不会放在(0,0)处。如果那样的话,你的解决方案就没问题。

要撤消翻译的效果,只需减去中心的坐标:

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