[英]Rotating points around another arbitrary point
给出函数内的以下测试代码:
int orientation = 0; // increments up to 359, then loops to 0
int tempx, tempy;
float radians = orientation * (M_PI / 180);
tempx = point->x;
tempy = point->y;
tempx = (int) (tempx * cos(radians) - tempy * sin(radians));
tempy = (int) (tempx * sin(radians) + tempy * cos(radians));
tempx = tempx + origin->x;
tempy = tempy + origin->y;
使用以下几点(相对于原点):( - (-100, 0)
, (0, -100)
, (0, 100)
(0, -100)
(0, 100)
我得到这个奇怪的情节:
蓝色和绿色线是重叠的路径。 中间的交叉点(几乎看不到黄点)是原点。 当orientation
为0
或180
时,所有点都在正确的位置,而在所有其他角度的非圆形路径中,所有点都在正确的位置。 在我的时间里,我做了很多线性代数,但这让我很难过。 我不确定我是否忽略了C本身的某些东西,或者我是否只是没有看到问题。
旋转后你正在重复使用tempx
。 请尝试以下方法:
tempx = (int) (point->x* cos(radians) - point->y* sin(radians));
tempy = (int) (point->x* sin(radians) + point->y* cos(radians));
看看是否能解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.