POV-Ray : Newsgroups : povray.newusers : Rotations not working as expected : Re: Rotations not working as expected Server Time
2 Nov 2024 09:19:41 EDT (-0400)
  Re: Rotations not working as expected  
From: Mike Williams
Date: 20 May 2004 00:04:25
Message: <KEnOvHAM3CrAFwi2@econym.demon.co.uk>
Wasn't it Alex Bame who wrote:
>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.

Imagine your mechanism as an inverted pyramid. The slope of the edges of
the pyramid (theta) is not the same as the slope of a line running up
the centre of one of the faces. Let's call the slope of the centre line
"alpha". You need to rotate the centres of your springs upwards by
alpha, not theta. The length of the spring also depends on alpha, not
theta.

My trig doesn't seem up to calculating alpha, so I got POV to do all the
hard work for me. I calculated the points P1 and P2 that are half way up
the first two rods and told POV to run the spring between those points.

// Need this for Point_At_Trans
#include "transforms.inc"

// Calculate the endpoints of one spring
#declare P1=<sin(theta)*sin(phi), cos(theta), sin(theta)*cos(phi)>;
#declare P2=<sin(theta)*sin(phi+pi/2), cos(theta),      
        sin(theta)*cos(phi+pi/2)>;

// Calculate its length
#declare Length = vlength(P2-P1);

// Declare the spring
#declare Spring= 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}

   translate <0,0.5,0>                // move one end point to <0,0,0>
   scale <1, Length, 1>               // Set the correct length
   transform {Point_At_Trans (P2-P1)} // point it in the P1-P2 direction
   translate P1                       // move one end from <0,0,0> to P1
}

// Make four copies
object {Spring}
object {Spring rotate <0, (pi)*180/pi, 0>}
object {Spring rotate <0, (pi/2)*180/pi, 0>}
object {Spring rotate <0, (3*pi/2)*180/pi, 0>}


-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

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