简体   繁体   English

围绕任意轴旋转平面2d对象

[英]Rotate flat 2d object around an arbitrary Axis

So I have a flat 2d Polygon and I would like to rotate each point of the Polygon around a axis defined by two 2d Points. 所以我有一个平面的2d多边形,我想围绕由两个2d点定义的轴旋转多边形的每个点。 These rotated points are later used to generate a 3d rotations object from the flat 2d Polygon. 这些旋转点稍后用于从平面2d多边形生成3d旋转对象。 So I got this at the moment: 所以我此刻得到了这个:

  1. Calculate the axis normal position of one polygon point. 计算一个多边形点的轴法线位置。
  2. From this point I calculate the matrix with a matrixLookAt(pointOnLine, polygonPoint, upVec) function 从这一点开始,我使用matrixLookAt(pointOnLine,polygonPoint,upVec)函数计算矩阵
  3. Then I rotate the matrix on the Z-Axis with 45° 然后我在Z轴上以45°旋转矩阵
  4. And finaly I multiply the polygonPoint with the computed matrix. 最后,我将polygonPoint与计算矩阵相乘。

But with this method I don't get any usefull results. 但是使用这种方法我没有得到任何有用的结果。

For better unterstanding: P1 & P2 are defining the axis Psrc is the polygonPoint and Pdest is the final point in 3d 为了更好地展示:P1和P2定义轴Psrc是polygonPoint而Pdest是3d中的最终点 在此输入图像描述

Far easier to be done. 更容易完成。 Just modify your model matrix before drawing using glRotatef() : 只需在使用glRotatef()绘制之前修改模型矩阵:

glRotatef(angle, vx, vy, vz);
  • angle is obviously the angle. angle显然是角度。
  • vx , vy , and vz are the vector defining your rotation axis. vxvyvz是定义旋转轴的矢量。

Or, to use it with 2 points given: 或者,使用它给出2分:

glRotatef(p1.x - p2.x, p1.y - p2.y, p1.z - p1.z);

If your rotation axis doesn't go through your world's origin, you'll have to adjust everything so your axis goes through the origin using glTranslatef() : 如果您的旋转轴没有通过您的世界原点,您将必须调整所有内容,以便您的轴使用glTranslatef()遍历原点:

glTranslatef(-p1.x, -p1.y, -p1.z); // move one point on the vector into the origin
glRotatef(p1.x - p2.x, p1.y - p2.y, p1.z - p1.z); // rotate everything
glTranslatef(p1.x, p1.y, p1.z); // move everything back into position

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM