本文介绍了C ++:围绕某个点旋转矢量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试在向量上围绕某个点旋转一个向量(在C ++中):
I am trying to rotate a vector around a certain point on the vector(in C++):
1 2 3
4 5 6
7 8 9
)(这是5)90度将导致:
rotated around the point (1,1) (which is the "5") 90 degrees would result in:
7 4 1
8 5 2
9 6 3
现在我正在使用:
x = (x * cos(90)) - (y * sin(90))
y = (y * cos(90)) + (x * sin(90))
但我不想让它旋转(0,0) / p>
But I don't want it rotated around (0,0)
推荐答案
由于对的帖子进行了评论,包括翻译回原始坐标系统的情况:
As Mehrdad Afshari commented on Pesto's post, including the translation back into the original coordinate system would be:
x_rotated = ((x - x_origin) * cos(angle)) - ((y_origin - y) * sin(angle)) + x_origin
y_rotated = ((y_origin - y) * cos(angle)) - ((x - x_origin) * sin(angle)) + y_origin
这篇关于C ++:围绕某个点旋转矢量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!