"Gautam " <gautam.s.muralidhar@gmail.com> wrote in message <gk0ime$8f1$1@fred.mathworks.com>...
> .......
> I am trying to write MATLAB code to rotate a point in 3space about an arbitrary axis. > .......
I like to think of rotation in terms of the dot and cross (inner and vector) products of vector analysis. If the axis of rotation points in a positive sense along the line from P1 = [x1,y1,z1] to P2 = [x2,y2,z2], and if the point Q = [x,y,z] is to undergo a righthand rotation by angle theta about this axis, then it will move to the point R as given by:
u = (P2P1)/norm(P2P1);
QP = QP1;
W = cross(u,QP);
R = P1 + dot(QP,u)*u + cross(W,u)*cos(theta) + W*sin(theta);
To get an insight into this last expression, the three righthand oriented vectors dot(QP,u)*u, cross(W,u), and W are mutually orthogonal with QP being the sum of the first two. (The equality QP = dot(QP,u)*u + cross(W,u) is an identity.) The vectors cross(W,u) and W have the same magnitude. The rotation through angle theta preserves the first of these components while rotating the remaining component in a circle lying in a plane parallel to the second and third vectors, cross(W,u) and W, so the one is multiplied by cos(theta) and the other by sin(theta).
Roger Stafford
