旋转矩阵-围绕旋转的盒子旋转一个球
Rotation matrix - rotate a ball around a rotating box
我有一个3D盒子:center point = (a,b,c)
, width = w
, height = h
, depth = d
。
中心点不是原点
我有一个球在盒子上(彼此触摸),它的center
和radius
。
我可以旋转盒子(围绕X轴,但其中心保持不变…),我希望球保持粘在盒子上。所以球需要和盒子一起旋转。
旋转角度为45度。
我试过这样做:
我定义了围绕X轴的旋转矩阵:
mat[3][3]
1, 0 , 0
0, cos(45), -sin(45)
0, sin(45), cos(45)
乘以球的中心矢量:
(ball.Center().m_x , ball.Center().m_y, ball.Center().m_z) * mat
所以我得到:
Point3D new_center(ball.Center().m_x,
ball.Center().m_y*cos(45) + ball.Center().m_z*sin(45),
-(ball.Center().m_y)*sin(45) + ball.Center().m_z*cos(45));
ball.Center() = new_center;
当盒子旋转太远时,球确实旋转了。我该怎么修理它?
您是否尝试将其转换为坐标原点,旋转然后再转换回来?
我认为坐标应该在右边乘以变换矩阵,即:
Point3D new_center(ball.Center().m_x,
ball.Center().m_y*cos(45) - ball.Center().m_z*sin(45),
ball.Center().m_y*sin(45) + ball.Center().m_z*cos(45);
ball.Center() = new_center;
感谢Alexander Mihailov,这里是最终答案:
//根据方框将球中心修正到原点。中心
Point3D ball_center_corrected = ball.Center() - box.Center();
//rotation_matrix(of X轴)* ball_center_corrected//所以旋转是围绕X轴
Point3D new_center(ball_center_corrected.m_x,
ball_center_corrected.m_y*cos(angle) -
ball_center_corrected.m_z*sin(angle),
ball_center_corrected.m_y*sin(angle) +
ball_center_corrected.m_z*cos(angle));
//将球的中心移回盒子周围
ball.Center() = new_center + box.Center();
相关文章:
- 旋转播放器模型以指向一个点
- 在 cpp 中围绕原点旋转一个点?
- 将四元数旋转的游戏对象旋转另一个四元数时出现问题
- 在 OpenGL 中旋转一个正方形
- 我如何仅使用一个Arduino uno才能在同一时间和同一方向上旋转两个步进电动机
- 如何将对象围绕另一个对象(C 和OGRE3D)旋转
- CAS 是一个像旋转一样的循环吗?
- 用数学方法旋转一个有序数字数组
- 如何正确旋转一个矢量以匹配另一个矢量?(OPENGL)
- 围绕另一个 3D 点旋转一个 3D 点
- 旋转一个对象面对另一个C
- 旋转一个向量以达到与另一个向量的正交性
- 如何旋转一个对象使其面向另一个对象
- 在二维中仅旋转一个四边形
- 旋转一个不对称的截头体
- 旋转矩阵-围绕旋转的盒子旋转一个球
- 用OpenCV围绕一个点旋转一个点
- 在DirectX中围绕质心旋转一个等边三角形
- Opengl旋转一个已经在旋转的物体,就像地球月球旋转一样
- 用欧拉角旋转一个四元数