I represent the form as a set of coordinates in 3D, I try to rotate the whole object around the axis (in this case, the Z axis, but I would like to rotate around all three as soon as I get it working).
I wrote the code for this using the rotation matrix:
//Coord is a 3D vector of floats //pos is a coordinate //angles is a 3d vector, each component is the angle of rotation around the component axis //in radians Coord<float> Polymers::rotateByMatrix(Coord<float> pos, const Coord<float> &angles) { float xrot = angles[0]; float yrot = angles[1]; float zrot = angles[2]; //z axis rotation pos[0] = (cosf(zrot) * pos[0] - (sinf(zrot) * pos[1])); pos[1] = (sinf(zrot) * pos[0] + cosf(zrot) * pos[1]); return pos; }
The figure below shows the object that I am trying to rotate (looking down on the Z axis) before trying to rotate, each small sphere indicates one of the coordinates that I am trying to rotate
alt text http://www.cs.nott.ac.uk/~jqs/notsquashed.png
The rotation is performed for the object using the following code:
The problem is that when I perform the rotation in this way, with the angle parameter set to (0,0,0,0,1,0), it works (kind of), but the object is deformed, for example:
alt text http://www.cs.nott.ac.uk/~jqs/squashed.png
what I do not want. Can someone tell me what I'm doing wrong, and how can I rotate an entire object around an axis without deforming it?
thanks
nodlams
source share