简体   繁体   中英

Rotate a grid of points in C++

If i had an array of point structs defined as

struct Point{

    float x;
    float y;

};

How would I rotate the points in this array by a given angle?

As an example:

例子

Any help would be appreciated!

float x_old = p.x; float y_old = p.y;
p.x = x_old * cos(a) - y_old * sin(a);
p.y = x_old * sin(a) + y_old * cos(a);

Of course, if you are rotating many points by the same angle, you will want to save the sin & cos, instead of calculating them twice per point.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM