C ++旋转2D形状列表

时间:2016-04-06 13:05:16

标签: c++ list rotation shapes

旋转具有给定度数的形状时,我遇到了一些问题。

void Shape::rotate(double degrees)
{
    // rotates the vertices of a shape by a specified angle in degrees

    int x, y, xx, yy;
    double radians;

    x = centroid.getX();
    y = centroid.getY();
    vertices.push_back(Vertex(x, y));

    x = vertices.back().getX() - centroid.getX();
    y = vertices.back().getY() - centroid.getY();

    radians = (degrees * PI) / 180;
    xx = round(x * cos(radians) - y * sin(radians));
    yy = round(y * cos(radians) + x * sin(radians));
    xx = xx + centroid.getX();
    yy = yy + centroid.getY();
    vertices.push_back(Vertex(xx, yy));

    radians = (degrees * PI) / 180;
    xx = round(x * cos(radians) - y * sin(radians));
    yy = round(y * cos(radians) + x * sin(radians));
    xx = xx + centroid.getX();
    yy = yy + centroid.getY();
    vertices.push_back(Vertex(xx, yy));

    radians = (degrees * PI) / 180;
    xx = round(x * cos(radians) - y * sin(radians));
    yy = round(y * cos(radians) + x * sin(radians));
    xx = xx + centroid.getX();
    yy = yy + centroid.getY();
    vertices.push_back(Vertex(xx, yy));
}

但我得到的输出是:

Messed up rhombus

我出错的任何想法?

0 个答案:

没有答案