[comp.graphics] how do i rotate around an arbitrary vector in 3D?

rodent@netcom.UUCP (Ben Discoe) (12/14/90)

i need to rotate a large set of points around an arbitrary axis,
specified as a vector.  i know how to rotate around any base axis
(since it's just 2D rotation).  If i had Mathematica around, i'd
just multiply the five rotation matrices involved, but i left
that behind when i left academia.

i figure you take the vector, find it's spherical coordinates theta phi,
then:	rotate -theta around z
	rotate -phi around y
	(original vector now lies along z^)
	rotate desired amount around z
	(then reverse the first two steps)
	rotate phi around y
	rotate theta around z

If these transformations simplify into a nice simple matrix, great!
The above assumes right-handed coords.  If someone knows the final
matrix, please specify which handedness you used.

In case anyone is interested, it's for a cartographic application.

Thanks!
---------
Ben Discoe, frustrated visionary at large.

wrf@mab.ecse.rpi.edu (Wm Randolph Franklin) (12/15/90)

In article <18733@netcom.UUCP> rodent@netcom.UUCP (Ben Discoe) writes:
>i need to rotate a large set of points around an arbitrary axis,
>specified as a vector.  i know how to rotate around any base axis
>(since it's just 2D rotation).  If i had Mathematica around, i'd
>just multiply the five rotation matrices involved, but i left
>that behind when i left academia.

For want of anything else, you might try:

%A Wm. Randolph Franklin
%T Efficient Rotation of an Object
%J IEEE Trans. Computer
%V C-32
%N 11
%D Nov. 1983
%P 1064-1067

I'll papermail a copy  if you give  me your address.  IMHO methods, such
as used by most texts, that first move the axis to the Z  axis are brain
damaged.  Their  conplexity   is baroque and  they're   numerically  ill
conditioned for certain axes.

Here is a vector formulation:  

   q := cos(t)*p + (1-cos(t))*dotprod(a,p)*a + sin(t)*crossprod(a,p)


'a' is the NORMALIZED axis.  This is a right hand rotation.  Converting
this to a matrix using Maple seems to give

                2
         [c + a1  (1 - c), a1 a2 (1 - c) - a3 s, a1 a3 (1 - c) + a2 s]

                                      2
         [a1 a2 (1 - c) + a3 s, c + a2  (1 - c), a2 a3 (1 - c) - a1 s]

                                                            2
         [a1 a3 (1 - c) - a2 s, a2 a3 (1 - c) + a1 s, c + a3  (1 - c)]


Here the point would be a column vector to  the right of the matrix.   I
think this is right, and it agrees with FvDF&H, page 227, ex 5.15, so it
probably is, sed caveat emptor lectorque.

-- 
						   Wm. Randolph Franklin
Internet: wrf@ecse.rpi.edu (or @cs.rpi.edu)    Bitnet: Wrfrankl@Rpitsmts
Telephone: (518) 276-6077;  Telex: 6716050 RPI TROU; Fax: (518) 276-6261
Paper: ECSE Dept., 6026 JEC, Rensselaer Polytechnic Inst, Troy NY, 12180

mpogue@vis01.dg.com (Mike Pogue) (12/18/90)

	Use the quaternion approach.  It's much simpler, and it falls right
out of the math.  Try "Graphics Gems" for an intro, and equations.

-- 
Mike Pogue
Data General Corp.		Speaking for myself, not my company....
Westboro, MA.