这是一个顺时针旋转的函数。参数是我们要旋转多少度。 怎么改成逆时针旋转?
void rotateClockwise( int degree ) {
int currentDegree = getDegree();
int desiredDegree = currentDegree + degree;
if( desiredDegree > 359 ) {
desiredDegree -= 359;
}
do {
newDegree = getDegree(); // Returns current degree
desiredDegreeSINE = sin(desiredDegree * (PI/180));
currentDegreeSINE = sin(newDegree * (PI/180));
if( desiredDegreeSINE > 0 && currentDegreeSINE < 0 ) {
newDegree = newDegree - 360;
}
if( newDegree >= desiredDegree ) {
// Stop rotating
break;
} else {
// Keep rotating
}
} while(true);
}
我们每时每刻旋转 1 度。
最佳答案
void rotateCounterClockwise( int degree ) {
return rotateClockwise(360 - (360 + degree) % 360);
}
关于c++ - 我怎样才能逆时针旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36418339/