2

I am developing a DXF parser by using the dxflib library. I have a problem parsing ellipses.

When I parse an ellipse I receive the following data:

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;
};

I am trying to compute the angle by using the following equation:

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

But it gives me wrong outcomes (for example if the angle is 16 degrees it gives to me about 74 degrees).

How should I compute properly the rotation angle?

4

1 回答 1

4

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

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

auto angle = std::atan2(ellipse.my - ellipse.cy, ellipse.mx - ellipse.cx);
于 2015-06-30T09:24:10.223 回答