POV-Ray : Newsgroups : povray.advanced-users : Rotate object to lie along a vector : Re: Rotate object to lie along a vector Server Time
29 Jul 2024 22:32:40 EDT (-0400)
  Re: Rotate object to lie along a vector  
From: Thomas Willhalm
Date: 4 Dec 2000 07:55:21
Message: <qqmk89g2vnq.fsf@pluto07.fmi.uni-konstanz.de>
"janger" <d_j### [at] hotmailcom> writes:

> This is probably a simple question, but I just can't work the damn thing
> out.
> I'm writing an L-System app for use with Povray. Let's say I have a cylinder
> lying along the positive x-axis, and I want to rotate it to be parallel to
> the current forward vector of the L-System. What is the best way to do this?
> I need it so any object can be substituted for the cylinder, hence object
> rotations are required, rather than creating an object 'in-situ'.

Remark that this isn't uniquely determined: If you rotate the object around
your vector, you get another solution. In case of a cylinder, it doesn't
make a difference, because of the symmetry of the cylinder. But if you
take a box instead of a cylinder, several (different) transformations 
fulfill your requirements.

For the calculation of one of them, the easiest way is probably to use the
following theorem:

  The rows of a matrix are the images of the unit vectors.

You want the first unit vector <1,0,0>, the one along the x-axis, to be mapped
to a given vector v=<v1,v2,v3>. The other unit vectors, <0,1,0> and <0,0,1>
should be mapped to vectors that are perpendicular to v. Let's call these
images u and w. One possibility to find such vectors is to use the cross
product of two vectors: Its result is a vector that is perpendicular to
the arguments of the cross product. We can use this as follows:

  u := v cross <1,0,0>
  w := v cross u

However, this doesn't work in the case that v is in x-direction, because then
u becomes <0,0,0>. (Fortunately for us, in this special case we don't need
any rotation.)

So, we get the following matrix:

     (v1 u1 w1)
 M = (v2 u2 w2)
     (v3 u3 w3)

For a point p, the multiplication M*p is (one of) the desired transformations.

If you don't know, what the cross product of the product of a matrix with a 
vector is, it is a good idea to have a look at a linear algebra book. You can 
also find some information about this in the documentation of POV-Ray.

I hope this helps
Thomas



-- 
http://www.thomas.willhalm.de/ (includes pgp key)


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.