POV-Ray : Newsgroups : povray.general : rotation of an object using orientation vectors ? Server Time
29 Nov 2024 00:51:40 EST (-0500)
  rotation of an object using orientation vectors ? (Message 1 to 5 of 5)  
From: Dav shef
Subject: rotation of an object using orientation vectors ?
Date: 17 Jun 2006 11:35:00
Message: <web.44941fa7b9a544229d1874140@news.povray.org>
Hi All,

I want to rotate an object. I couls use the rotate command but this function
is defined by the use of angles. Instead, I want to use units vectors that
describe the orientation.
knowing the orientation vector of my object (for example i = <1,0,0>), I
want to rotate this object such that the new orientation is, let's say, u =
<0,1,0>.

The code below creates a cylinder, coloured half blue and half red.
then I use a macro to rotate it. for that, I calculate the three Euler
angles and then use the command matrix to perform the three rotations for
each dimension x, y and z.

Problem : it doesn't work properly. For example, the transformation:

<1,0,0>) --> <0,1,0> doesn't work at all, but
<1,0,0>) --> <0,0,1> does !!

I Don't understand what is wrong ? (the angles calculation ?, the rotation
matrixes ? me ?). Can someone crack this ? Or has someone has a better
solution ?

Cheers

David





#declare MyObject = union{

       cylinder{<0,0,0>,<3,0,0>,0.5 open texture { pigment { color 0,0,1>
}}}
       cylinder{<3,0,0>,<6,0,0>,0.5 open texture { pigment { color<1,0,0>
}}}

}

object{

MyObject
align(<1,0,0>,<0,1,0>)

      }

//=================================================

#macro align(i_vector,u_vector)

  #local i_x = vdot( x, i_vector );
  #local i_y = vdot( y, i_vector );
  #local i_z = vdot( z, i_vector );

  #local u_x = vdot( x, u_vector );
  #local u_y = vdot( y, u_vector );
  #local u_z = vdot( z, u_vector );

#local angl_z =
acos((u_x*i_x+u_y*i_y)/(sqrt(u_x*u_x+u_y*u_y)*sqrt(i_x*i_x+i_y*i_y)));

#local angl_y =
acos((u_x*i_x+u_z*i_z)/(sqrt(u_x*u_x+u_z*u_z)*sqrt(i_x*i_x+i_z*i_z)));

#local angl_x =
acos((u_y*i_y+u_z*i_z)/(sqrt(u_y*u_y+u_z*u_z)*sqrt(i_y*i_y+i_z*i_z)));


       matrix< 1,0,0,
               0,cos(angl_x),sin(angl_x),
               0,-sin(angl_x),cos(angl_x),
               0,0,0 >

       matrix< cos(angl_y),0,-sin(angl_y),
               0,1,0,
               sin(angl_y),0,cos(angl_y),
               0,0,0 >

       matrix< cos(angl_z),sin(angl_z),0,
               -sin(angl_z),cos(angl_z),0,
               0,0,1,
               0,0,0 >

#end


Post a reply to this message

From: Zeger Knaepen
Subject: Re: rotation of an object using orientation vectors ?
Date: 17 Jun 2006 14:08:12
Message: <4494450c$1@news.povray.org>
why don't you use Reorient_Trans(Axis1, Axis2) or Point_At_Trans(YAxis) 
?

cu!
-- 
#macro G(b,e)b+(e-b)*C/50#end#macro _(b,e,k,l)#local C=0;#while(C<50)
sphere{G(b,e)+3*z.1pigment{rgb G(k,l)}finish{ambient 1}}#local C=C+1;
#end#end _(y-x,y,x,x+y)_(y,-x-y,x+y,y)_(-x-y,-y,y,y+z)_(-y,y,y+z,x+y)
_(0x+y.5+y/2x)_(0x-y.5+y/2x)            // ZK http://www.povplace.com


Post a reply to this message

From: darenw
Subject: Re: rotation of an object using orientation vectors ?
Date: 19 Jun 2006 21:35:00
Message: <web.44974fb1c155ffd78c5ce0670@news.povray.org>
If you are given three orthogonal unit vectors, or two from which the third
would be their cross product, describing the orientation of the rotated
object, those vectors *are* the columns (or rows?) of the rotation matrix
you want.  If i understand the question correctly, this is what you're
looking for.

Suppose you start with <1,0,0>,  <0,1,0>, and <0,0,1> vectors glued onto
your object, and your object rotates so that now you have vectors U,V,W.
then the matrix to perform that rotation would be
  matrix< U[0], U[1], U[2],
          V[0], V[1], V[2],
          W[0], W[1], W[2],
          0, 0, 0>

(or maybe the transpose; i just had a Mike's Hard Lemonade, got tipsy. i'm
never sure of anything anyway...)

Note that you need at least two unit vectors stuck to your object. Only one
would lead to ambiguity, allowing an axis of rotation about which the
object isn't nailed down.

Does this answer the question?

DSW


Post a reply to this message

From: darenw
Subject: Re: rotation of an object using orientation vectors ?
Date: 19 Jun 2006 21:55:01
Message: <web.449754efc155ffd78c5ce0670@news.povray.org>
"darenw" <Gre### [at] comcastnet> wrote:

>   matrix< U[0], U[1], U[2],
>           V[0], V[1], V[2],
>           W[0], W[1], W[2],
>           0, 0, 0>
>

Duh!  I meant  U.x, U.y, U.z and so on, not anything with square brackets.
I hop too often between C++, ruby, IDL and povray.

Embarrassed,
DSW.


Post a reply to this message

From: Dav shef
Subject: Re: rotation of an object using orientation vectors ?
Date: 27 Jun 2006 13:40:00
Message: <web.44a16c8ac155ffd7542d37840@news.povray.org>
Thanks guys...I'll try this out and come back here to post the results...
Have been very busy these days so I am sorry I didn't reply earlier than
that

Cheers !


Post a reply to this message

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