c++ - 求旋转椭圆的角度

标签 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 度)。

如何正确计算旋转角度?

最佳答案

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

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

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

关于c++ - 求旋转椭圆的角度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31134284/

相关文章:

c++ - 通过指针返回值

swift - Scenekit 物理 - 防止碰撞时旋转

android - 如何制作带滚动条的弧形菜单?

javascript - 三 Angular 学根据加速度计数据计算倾斜 Angular

javascript - 有没有一种方法可以在不使用三 Angular 函数的情况下处理 Angular (Javascript)

c++根据另外2个点计算2个点

c++ - 使用 cmake 和 CLion 调试和执行 QT 项目

java - 如何围绕另一个点旋转一个点

java - 根据角度绕圆画一条线

android - Android 支持弱符号吗?