Rotation matrix from a vector?

David Gobbi dgobbi at irus.rri.on.ca
Mon May 15 13:35:31 EDT 2000


Hi Scott,

Here is one possibility:  If the old axis is _a_ and the new axis
is _a'_, use

theta = acos(_a_ dot _a'_)    (where 'dot' means dot product)
_axis_ = _a_ cross _a'_       (cross product)

then 

RotateWXYZ(theta,axis[0],axis[1],axis[2])   

will provide the desired rotation.  Don't forget to do the 
radians-to-degrees conversion before calling RotateWXYZ.


A much more efficient way to it if the original axis _a_ is
always the x axis is to build the matrix yourself.  First,
you need to find two vectors _b'_ and _c'_ which are
perpendicular to _a'_.  You can use vtkMath::Perpendiculars()
for this if you have a recent version of VTK.

Then, build the matrix by inserting the vectors into the matrix 
columns:

   a'[0]  b'[0]  c'[0]  t[0]  
   a'[1]  b'[1]  c'[1]  t[1]
   a'[2]  b'[2]  c'[2]  t[2]
   0      0      0      1

where _t_ is the translation you wish to apply after the rotation.

 - David

--
  David Gobbi, MSc                    dgobbi at irus.rri.on.ca
  Advanced Imaging Research Group
  Robarts Research Institute, University of Western Ontario

On Mon, 15 May 2000, Harris Scott R CIV AFRL/SNJM wrote:

> I'd like to be able to use vtkDiskSource (and vtkCylinder Source) with a vector that specifies the
> orientation of the object. Does anyone have a simple recipe that takes a vector and then generates 
> a transformation matrix that will make a given axis (say x) parallel to the given vector?
> I think I saw something like this in one of the graphics gems books, but I haven't had time to 
> go and look it up
> 
> I'm working on a project where I'd like to visualize a lot of cylinders and disks that are arranged
> with given locations and orientations.
> 
> Thanks,
> -Scott Harris
> --------------------------------------------------------------------
> This is the private VTK discussion list. Please keep messages on-topic.
> Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
> To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
> <majordomo at public.kitware.com>. For help, send message body containing
> "info vtkusers" to the same address.
> --------------------------------------------------------------------
> 

--------------------------------------------------------------------
This is the private VTK discussion list. Please keep messages on-topic.
Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
<majordomo at public.kitware.com>. For help, send message body containing
"info vtkusers" to the same address.
--------------------------------------------------------------------



More information about the vtkusers mailing list