Hello,
I am currently working on a problem which I can't seem to solve.
I am trying to move a set of point around a sphere by a certain angle (or, preferably, by a distance, but most of the math examples I have found use angles).
What I am currently doing is as follows:
Convert the set of points from Cartesian (XYZ) coordinates to Spherical Coordinates,
Use Rodrigues Rotation formula to get "vRot", the rotation vector,
Multiply vRot with the original Spherical coordinates to get the new position.
According to Gnuplot, I can successfully convert the points to Spherical Coordinates, but I am having problems with the next two steps.
The equation for Rodrigues formula that I am using is this one:
Which I got from here:
http://stackoverflow.com/questions/26453951/rotateing-vector-on-plane-in-3d
This is the relevant section of code:
F32 x = renderlist[i].point.x;
F32 y = renderlist[i].point.y;
F32 z = renderlist[i].point.z;
//Values are between -1 and +1, this ensures all values are positive, since negative values seem to cause issues:
F32 xscaled = x+1;
F32 yscaled = y+1;
F32 zscaled = z+1;
//convert to spherical coordinates:
F32 radialdistance_r = sqrt(xscaled*xscaled + yscaled*yscaled + zscaled*zscaled);
F32 polarangle_theta = mAcos(zscaled / radialdistance_r);//0-PI
F32 azimuthalangle_phi = mAtan2(yscaled, xscaled); //0-2PI
//Using Rodrigues rotation forumula, as given here:
//http://stackoverflow.com/questions/26453951/rotateing-vector-on-plane-in-3d
Point3F v = Point3F(radialdistance_r, polarangle_theta, azimuthalangle_phi);
Point3F k = Point3F(0, 1, 0); //rotate on y axix
F32 theta = 0.0174533;// rotate by 1 degree only for now
Point3F vRot = v*mCos(theta) + mCross(k, v)*mSin(theta) + k*mDot(k, v)*(1 - mCos(theta));
Point3F newpos = v * vRot;
Con::printf("%f %f %f", newpos.x, newpos.y, newpos.z);
Is there anything obviously wrong here?
Thanks!