POV-Ray : Newsgroups : povray.newusers : Rotations not working as expected : Rotations not working as expected Server Time
30 Jul 2024 10:21:51 EDT (-0400)
  Rotations not working as expected  
From: Alex Bame
Date: 19 May 2004 20:45:00
Message: <web.40abfeb5584f13db4980b800@news.povray.org>
I think I'm missing something in how the rotation mechanism is supposed to
work.  I'm attempting to model a system composed of 4 rods seperated by 90
degrees from one another (or rather, their projections into the X-Z plane
are) that are rotated off the Y axis by some angle theta.  The rods are
additionally rotated around the Y axis by some angle phi.  Halfway up each
of the rods is a spring connecting each adjacent rod.  I am using an
isosurface and the f_helix1 function to draw the spring, then I'm scaling
it to the appropriate length (thus maintaining a constant number of loops)
and translating it up the vertical axis and performing the same rotation
(with an extra 45 degrees around the vertical axis so that it's connecting
the rods rather than in the middle of them) but the springs seem to have
'missed', i.e. they seem to have rotated more off the vertical axis than
the rods have.  I've been poking at this for hours now and can't figure out
what I'm missing :-

Here's the code I'm using, thanks in advance to anyone who takes the time to
glance at it for me.

--SNIP--
#include "colors.inc"
#include "metals.inc"
#include "functions.inc"

#declare cyl_radius=0.07;
#declare spr_maj_radius=0.05;
#declare spr_min_radius=0.01;

#declare phi=0;
#declare theta=pi/4;

camera {
   location <0, 3, -3>
   look_at <0, 1, 0>
}

// The rods

cylinder {
   <0, 0, 0>,     // Center of one end
   <0, 2, 0>,     // Center of other end
   cyl_radius     // Radius
   texture {
      T_Chrome_3A // Pre-defined texture
      scale 4     // Scale by the same ammount in all directions
   }
   rotate <0, 0, theta*180/pi>
   rotate <0, phi*180/pi, 0>
}

cylinder {
   <0, 0, 0>,     // Center of one end
   <0, 2, 0>,     // Center of other end
   cyl_radius     // Radius
   texture {
      T_Chrome_3A // Pre-defined texture
      scale 4     // Scale by the same ammount in all directions
   }
   rotate <0, 0, theta*180/pi>
   rotate <0, (phi+pi/2)*180/pi, 0>
}

cylinder {
   <0, 0, 0>,     // Center of one end
   <0, 2, 0>,     // Center of other end
   cyl_radius     // Radius
   texture {
      T_Chrome_3A // Pre-defined texture
      scale 4     // Scale by the same ammount in all directions
   }
   rotate <0, 0, theta*180/pi>
   rotate <0, (phi+pi)*180/pi, 0>
}

cylinder {
   <0, 0, 0>,     // Center of one end
   <0, 2, 0>,     // Center of other end
   cyl_radius     // Radius
   texture {
      T_Chrome_3A // Pre-defined texture
      scale 4     // Scale by the same ammount in all directions
   }
   rotate <0, 0, theta*180/pi>
   rotate <0, (phi+3*pi/2)*180/pi, 0>
}

// The springs

isosurface {
   function {
      f_helix1(x, y, z, 1, 20*pi,
         spr_min_radius, spr_maj_radius,
         1, 1, 0)
   }
   max_gradient 3
   contained_by{ box {-1/2,1/2} }   // One unit long, this gives us a
constant
   texture {                        // number of twists in the spring
      T_Brass_3A
      scale 4
   }
   scale <1, sqrt(2)*sin(theta), 1> // Scale the spring to the proper length
   rotate <0, 0, 90>
   translate <0, 1, 0>
   rotate <0, 90, 0>
   rotate <0, 0, theta*180/pi>
   rotate <0, (phi+pi/4)*180/pi, 0>
}

isosurface {
   function {
      f_helix1(x, y, z, 1, 20*pi,
         spr_min_radius, spr_maj_radius,
         1, 1, 0)
   }
   max_gradient 3
   contained_by{ box {-1/2,1/2} }
   texture {
      T_Brass_3A
      scale 4
   }
   scale <1, sqrt(2)*sin(theta), 1>
   rotate <0, 0, 90>
   translate <0, 1, 0>
   rotate <0, 90, 0>
   rotate <0, 0, theta*180/pi>
   rotate <0, (phi+3*pi/4)*180/pi, 0>
}

isosurface {
   function {
      f_helix1(x, y, z, 1, 20*pi,
         spr_min_radius, spr_maj_radius,
         1, 1, 0)
   }
   max_gradient 3
   contained_by{ box {-1/2,1/2} }
   texture {
      T_Brass_3A
      scale 4
   }
   scale <1, sqrt(2)*sin(theta), 1>
   rotate <0, 0, 90>
   translate <0, 1, 0>
   rotate <0, 90, 0>
   rotate <0, 0, theta*180/pi>
   rotate <0, (phi+5*pi/4)*180/pi, 0>
}

isosurface {
   function {
      f_helix1(x, y, z, 1, 20*pi,
         spr_min_radius, spr_maj_radius,
         1, 1, 0)
   }
   max_gradient 3
   contained_by{ box {-1/2,1/2} }
   texture {
      T_Brass_3A
      scale 4
   }
   scale <1, sqrt(2)*sin(theta), 1>
   rotate <0, 0, 90>
   translate <0, 1, 0>
   rotate <0, 90, 0>
   rotate <0, 0, theta*180/pi>
   rotate <0, (phi+7*pi/4)*180/pi, 0>
}

light_source { <2, 4, -3> color White }
light_source { <-2, -4, -3> color White }
--SNIP--

Sorry for the verbosity, while loops are next on my list of things to figure
out :)

-- Alex


Post a reply to this message

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