POV-Ray : Newsgroups : povray.advanced-users : Rotate object to lie along a vector Server Time
30 Jul 2024 00:20:49 EDT (-0400)
  Rotate object to lie along a vector (Message 1 to 7 of 7)  
From: janger
Subject: Rotate object to lie along a vector
Date: 22 Nov 2000 19:16:24
Message: <3a1c61d8@news.povray.org>
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'.
If anyone knows of some free Delphi source for Lsystems, I'd appreciate the
link.
Thanx
Janger


Post a reply to this message

From: Pabs
Subject: Re: Rotate object to lie along a vector
Date: 22 Nov 2000 19:23:56
Message: <3A1C63F0.1327B074@hotmail.com>
janger wrote:

> 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?

Look at the pov links page for John Vansickles page & get his Reorient macro
--
Bye
Pabs


Post a reply to this message

From: Christoph Hormann
Subject: Re: Rotate object to lie along a vector
Date: 23 Nov 2000 10:13:37
Message: <3A1D3420.ABD484B1@schunter.etc.tu-bs.de>
janger wrote:
> 
> If anyone knows of some free Delphi source for Lsystems, I'd appreciate the
> link.

The Lparser source code (in C) is available on:

http://www.xs4all.nl/~ljlapre/

might be a good inspiration for your own work.

Christoph

-- 
Christoph Hormann <chr### [at] gmxde>
Homepage: http://www.schunter.etc.tu-bs.de/~chris/


Post a reply to this message

From: janger
Subject: Re: Rotate object to lie along a vector
Date: 23 Nov 2000 13:27:58
Message: <3a1d61ae@news.povray.org>
"Christoph Hormann" <Chr### [at] schunteretctu-bsde> wrote in
message news:3A1D3420.ABD484B1@schunter.etc.tu-bs.de...
>
> The Lparser source code (in C) is available on:
>
> http://www.xs4all.nl/~ljlapre/
>
> might be a good inspiration for your own work.
>
> Christoph
>
> --
> Christoph Hormann <chr### [at] gmxde>
> Homepage: http://www.schunter.etc.tu-bs.de/~chris/

I've actually looked at this code already. Unfortunately my C code
understanding went down along with my brain when I started suffering from
depression :-) The code has helped a bit, but that's why I was after some
Delphi code. I'm not sure if it exists though.


Post a reply to this message

From: Thomas Willhalm
Subject: Re: Rotate object to lie along a vector
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

From: David Fontaine
Subject: Re: Rotate object to lie along a vector
Date: 4 Dec 2000 23:21:30
Message: <3A2C6CA0.39FDDDFA@faricy.net>
It will be... (counting on fingers) ...too long before I have a vectors and
matrices course. Math moves so slow.

--
David Fontaine  <dav### [at] faricynet>  ICQ 55354965
My raytracing gallery:  http://davidf.faricy.net/


Post a reply to this message

From: Thomas Willhalm
Subject: Re: Rotate object to lie along a vector
Date: 5 Dec 2000 03:39:15
Message: <qqmofyrb6to.fsf@pluto07.fmi.uni-konstanz.de>
David Fontaine <dav### [at] faricynet> writes:

> It will be... (counting on fingers) ...too long before I have a vectors and
> matrices course. Math moves so slow.

Vectors and matrices aren't so difficult, in particular if you only need
two and three dimensional vectors.

Asking google, I have found a web page for you:
http://www.cs.cmu.edu/~rapidproto/handouts/vectors.html
It is a rather compact description of what you should know about vectors
for your purpose. Since the information density is quite high, don't
get frustrated, if you need several weeks to digest it. Then reread what
I wrote. 

Afterwards you will agree that vectors are exactly what you need
for your POV-Ray projects (probably you already used them without noticing).

Bye
Thomas

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


Post a reply to this message

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