我怎样才能逆时针旋转
How can I rotate counterclockwise
这是一个用于顺时针旋转的函数。参数是我们想要旋转的度数。如何将其更改为逆时针旋转?
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);
}
int rotateClockwise(int degree) {
return (getDegree() + degree) % 360;
}
和
int rotateCounterClockwise(int degree) {
int desiredDegree = (getDegree() - degree%360);
return desiredDegree >= 0 ? desiredDegree : 360+desiredDegree;
}
简化它。
你已经有了一个旋转方向——这是你旋转角度的标志。
#include <iostream>
struct thing
{
int rotate(int alpha)
{
angle = (angle + alpha) % 360;
if (angle < 0)
angle += 360;
// by all means pre-calculate sin and cos here if you wish.
return angle;
}
int angle;
};
int main(int argc, char * argv[])
{
auto t = thing { 10 };
std::cout << t.rotate( 5 ) << std::endl;
std::cout << t.rotate( -30 ) << std::endl;
std::cout << t.rotate( 360 + 30 ) << std::endl;
std::cout << t.rotate( -360 - 40 ) << std::endl;
return 0;
}
预期结果:
15
345
15
335
相关文章:
- 与互斥锁相比,旋转锁可以保证上下文切换
- 绘制旋转的三角形
- 旋转模型矩阵时的形状失真
- 四边形的 2D 旋转
- 垂直方向的 Gtk3+ 旋转按钮 (c/c++)
- 发布旋转矩阵(openGL/glm)
- 顺时针迭代旋转 3 位数字
- 形状对象的旋转和缩放不正确C++
- 如何在 OpenSceneGraph 中缩放/旋转/移动资产
- 如何有效地计算将单位立方体映射到自身的反射和旋转?
- 子轴围绕父轴而不是他自己的轴旋转
- 将使用太多的纹理插值器 - 带旋转的着色器
- SFML 向下移动时如何围绕屏幕中心旋转?
- 如何在OpenGL中正确旋转和缩放对象?
- 使用 C++在 OpenGL 中移动自动旋转的 3D 多边形
- 按时间自动旋转形状,同时在 OpenGL 中使用C++移动它们
- 将矩阵逆时针旋转 180 度的问题
- 我怎样才能逆时针旋转
- 顺时针和逆时针旋转阵列的有效方式
- 这个代码是逆时针还是顺时针旋转关于叉积的点云