The rotation and translation of a rectangle
Here I'm wondering if a rectangle can remain rectangular after a rotation and translation. My example is listed as follow:
The four corner points of original rectangle is s1(-1,-1,2), s2(-1,1,2), s3(1,1,2), s4(1,-1,2);
My whole transform is a translation and a rotation, so I use glTranslate and glRotate to get the transform-matrix:
GLfloat modelView[16]; //transform the rectangle
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
//because of column-major order, here should be rotation first and then translation
glRotatef(-rotationAngel, rotationVector[0], rotationVector[1], rotationVector[2]);
glTranslatef(tranV[0], tranV[1], tranV[2]);
glGetFloatv(GL_MODELVIEW_MATRIX, modelView);
glPopMatrix();
In my real program, rotationAngel = 62, rotationVector = (-0.34, 0.81, 0), tranV = (0.46, 1.70, 0.059);
Then I use matrix "modeView to calculate four corner points of my result rectangle:
sp1.x = s1.x*modelView[0] + s1.y*modelView[4] + s1.z*modelView[8] + modelView[12];
sp1.y = s1.x*modelView[1] + s1.y*modelView[5] + s1.z*modelView[9] + modelView[13];
sp1.z = s1.x*modelView[2] + s1.y*modelView[6] + s1.z*modelView[10] + modelView[14];
The other three sp2 sp3 sp4 is calculated in the same way.
However, the result is confusing. They are not a rectangle anymore.
sp1 = (-2.10, -0.038, 0.77);
sp2 = (-2.48, 1.88, 1.45);
sp3 = (-1.38, 1.50, 3.08);
sp4 = (-1.01, -0.34, 2.39);
Obviously, after drawing them in OpenGL, the four corner points cannot make a rectangle.
So I wanna know why? Translation and rotation cannot ensure a rectangle unchangeable? And how to make a rectangle remain rectangular after these transformation?
Translation and Rotation are types of transformations that are known as Rigid Transformations, they preserve distance and orientation between vertexes, so, basicaly, after translating and rotating, a rectangle should keep its shape.
Actually there is no problem in your code, if you calculate the distance (d = sqrt(<v1 - v0, v1 - v0>), where <x, y> denotes the inner product) between any pair consecutives vertexes, you get 2, which is the original distance between any pair of consecutives vertexes in your rectangle prior the transformation, and if you take the dot product of the normalized vectors (sp2 - sp1) and (sp4 - sp1) the result is very close to 0 (due to floating errors), wich indicates that the forming angle is very close to 90 degrees. So, after the transformation, you're still getting a rectangle in space.
链接地址: http://www.djcxy.com/p/64016.html上一篇: 仿射变换给出4分
下一篇: 矩形的旋转和平移