POV-Ray : Newsgroups : povray.newusers : Positioning an object in 3 space. Server Time
1 Nov 2024 19:13:31 EDT (-0400)
  Positioning an object in 3 space. (Message 1 to 4 of 4)  
From: Carl
Subject: Positioning an object in 3 space.
Date: 21 Jan 2005 14:20:00
Message: <web.41f154ee97df0f1a54c62600@news.povray.org>
I have an object with a defined up (say the y-direction) and a defined
forward (say the x-direction).  I'd like to place this object at a new
location with a new orientation specified by given new up and forward
vectors.  Both vectors are unit vectors and they at perpendicular to each
other.  The translate part is easy but the rotations I need to apply to my
object are giving me trouble.  I'm sure I'm making things more complicated
then necessary.  Can someone help?

Thanks,
Carl


Post a reply to this message

From: Mike Williams
Subject: Re: Positioning an object in 3 space.
Date: 21 Jan 2005 16:03:00
Message: <0B3+vIAR3W8BFwZQ@econym.demon.co.uk>
Wasn't it Carl who wrote:
>I have an object with a defined up (say the y-direction) and a defined
>forward (say the x-direction).  I'd like to place this object at a new
>location with a new orientation specified by given new up and forward
>vectors.  Both vectors are unit vectors and they at perpendicular to each
>other.  The translate part is easy but the rotations I need to apply to my
>object are giving me trouble.  I'm sure I'm making things more complicated
>then necessary.  Can someone help?

I always found this a bit tricky. Applying Reorient_Trans() twice
sometimes seemed to cause the thing to get tilted the wrong way. Then
Michael Andrews developed his Three_Point_Trans() that does the whole
thing - translation and rotations.

#macro Three_Point_Trans(T1a, T1b, T1c, T2a, T2b, T2c)
   transform {
     #local Y = vnormalize(T1b - T1a);
     #local X = vnormalize(T1c - T1a);
     #local Z = vnormalize(vcross(X, Y));
     #local X = vcross(Z, Y);
     #local T = Shear_Trans(X, Y, Z)
     translate -T1a
     transform { T inverse }
     #local Y = vnormalize(T2b - T2a);
     #local X = vnormalize(T2c - T2a);
     #local Z = vnormalize(vcross(X, Y));
     #local X = vcross(Z, Y);
     Shear_Trans(X, Y, Z)
     translate T2a
   }
#end
/*
The three points a,b,c define a triangle; a is the origin, b-a is the 
primary orientation and abc gives a secondary orientation plane. The two 
orientation axes b-a and c-a do not have to be orthogonal, just 
independant so vcross(b-a,c-a) doesn't return a zero length vector.

So Three_Point_Trans(0,y,x, P0,P1,P2) gives a transform from the origin 
to P0, aligns y with P1-P0 and puts the (x,y) plane in the plane of the 
(P0,P1,P2) triangle.

*/
-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From: Slime
Subject: Re: Positioning an object in 3 space.
Date: 21 Jan 2005 21:54:26
Message: <41f1c062$1@news.povray.org>
> I have an object with a defined up (say the y-direction) and a defined
> forward (say the x-direction).  I'd like to place this object at a new
> location with a new orientation specified by given new up and forward
> vectors.

This is practically what matrix transformations are *for*. The matrix
transformation can be thought of as four vectors: what the X axis is mapped
to, what the Y axis is mapped to, what the Z axis is mapped to, and what to
translate by afterwards. So let's say you have the two vectors that you want
to map the Y and X axes to, called newydir and newxdir. First, you calculate
what you'll be mapping the Z axis to via a cross product (assuming newydir
and newxdir are normalized):

#declare newzdir = vcross(newxdir, newydir);

Then you just use a matrix transformation like so:

matrix <
    newxdir.x, newxdir.y, newxdir.z,
    newydir.x, newydir.y, newydir.z,
    newzdir.x, newzdir.y, newzdir.z,
    transamnt.x, transamnt.y, transamnt.z
>

where transamnt is where you want to translate the object to.

 - Slime
 [ http://www.slimeland.com/ ]


Post a reply to this message

From: Carl
Subject: Re: Positioning an object in 3 space.
Date: 24 Jan 2005 19:50:00
Message: <web.41f5973c2ea30929a54c62600@news.povray.org>
Thanks for the help guys.  I sure was making things harder then needed.
Thanks for setting me strait.

Carl


Post a reply to this message

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