I am currently trying to simulate rotations of a 3d model in a C++ problem, but am a bit perplexed by the behaviour of my program. I had considered posting this in stackoverflow.com, but the problem seems to be more down to my lack of understanding of the maths. The following code statement takes a 3d point v1 (where v1[0] is x, v1[1] is y and v1[2] is z), and rotates the points around the xAxis using a theta value of "rotationX" given in radians:
newY = cos(rotationX)*v1[1] - sin(rotationX)*v1[2];
newZ = sin(rotationX)*v1[1] + cos(rotationX)*v1[2];
v1[1] = newY;
v1[2] = newZ;
The issue I am having is that when sweeping through values of rotationX, when the value of rotationX switches from negative to positive (or vice versa), the rotation seems to change direction. For example, if I am decrementing rotationX from 0.4, 0.3, 0.2, 0.1, 0.0 and it is rotating "clockwise", when I hit -0.1, the rotation "reverses" and starts to go back the way rotating "counter-clockwise". What I want is a formula for which I can continually increment or decrement rotationX and it will continue on rotating forever in the same direction.
I have tried running a few toy values through this formula to see if I can convince myself of what is going wrong, but I am a bit lost. Where am I going wrong?