POV-Ray : Newsgroups : povray.general : Spiral tube? : Re: Spiral tube? Server Time
19 May 2024 20:49:51 EDT (-0400)
  Re: Spiral tube?  
From: Stephen
Date: 6 Jan 2016 05:17:47
Message: <568ce9cb@news.povray.org>
On 1/6/2016 5:48 AM, Mike Horvath wrote:
> How do I create a spiral tube, like a spring? Like this:
>
> http://www.f-lohmueller.de/pov_tut/animate/anim16e.htm
>
> but a single object, not a union of spheres?
>
> Thanks!
>

Many years ago I asked a similar question and was given a macro to 
create spiral tubes consisting of torus-segments. It is not a single 
object but it is contiguous. The annotations are mostly by Frank 
(Sputnik) and it is just pulled out of an old scene of mine. It is a 
long spring with the helix tightening at the ends.


#declare Y_Adjust = 0 ;                                // <- Mine
// Spring_with_Ends
// Spring_Sputnik
// Spiral  by Sputnik

#declare RotSpeed =  -9720*(frame_number/599 );        // <- Mine

#declare HeightOffset = 6.5 ; //11.750;
#declare SpringHeight =  13  ;
#declare SpringMajorRadius = .4;          //2;
#declare SpringMinorRadius = .060;
#declare SpringRevolutions = 24;
#declare SpringSegments = 5*SpringRevolutions ; // 5*SpringRevolutions is
                               // enough for #macro Spiral

#declare SpringHeight2 = 0.5;
#declare SpringRevolutions2 = 2;
#declare SpringSegments2 = 5*SpringRevolutions2; // 5*SpringRevolutions is
                               // enough for #macro Spiral
#declare SpringHeight3  = 0.5;
#declare SpringRevolutions3 = 2;
#declare SpringSegments3 = 5*SpringRevolutions3; // 5*SpringRevolutions is
                               // enough for #macro Spiral

// SPIRAL 
///////////////////////////////////////////////////////////////////

#macro Spiral ( Radius1, Radius0, Rise, Turns, Segments )

   // Radius1 : major radius
   // Radius1 : minor radius
   // Rise    : height of a single turn
   // Turns   : number of turns (may be non-integer)
   // Segments: number of tori in spiral
   //           (>= 2*Turns; usually 5*Turns ... 10*Turns is enough)

   // some calculations ...
   #local Ang= Turns*360/Segments;
   #local Ri = Rise/2 * Turns/Segments;
   #local Sin= sin(radians(Ang/2));
   #local A  = Radius1*Sin;
   #local B  = sqrt(Radius1*Radius1-A*A);
   #local C  = A*A/B;
   #local DD = Ri*Ri+A*A;
   #local E  = DD/C;
   #local W  = degrees(atan2(C,sqrt(DD)));
   #local R  = sqrt(E*(E+C));

   // single torus-segment
   #declare T =
     intersection {
       torus { R, Radius0 }
       plane { -x, 0 rotate  W*y }
       plane {  x, 0 rotate -W*y }
       bounded_by { box {
         1.001*<-(R+Radius0)*Sin, -Radius0, -(R+Radius0)>,
         1.001*< (R+Radius0)*Sin,  Radius0, -(R-Radius0)*(1-Sin*Sin)>
         } }
       rotate -degrees(atan2(Ri,A))*z
       translate <0, Ri, E-B>
       rotate Ang/2*y
       }
   // stack the segments
   union {
     #local N = 0;
     #while (N<Segments)
       object { T rotate N*Ang*y translate N*2*Ri*y }
       #local N = N+1;
       #end//while
     // no "}" to allow modifiers
   #end//macro Spiral

/////////////////////////////////////////////////////////////////////////////

   // spring consisting of torus-segments
   #declare Spring =
     Spiral (
       SpringMajorRadius,
       SpringMinorRadius,
       SpringHeight/SpringRevolutions,
       SpringRevolutions,
       SpringSegments // 5*SpringRevolutions usually is enough
       ) /* { */ rotate -90*y /* same orientation as Warp's spring */ }


   #declare Spring2 =
     Spiral (
       SpringMajorRadius,
       SpringMinorRadius,
       SpringHeight2/SpringRevolutions2,
       SpringRevolutions2,
       SpringSegments2 // 5*SpringRevolutions usually is enough
       ) /* { */ rotate -90*y /* same orientation as Warp's spring */ }


   #declare Spring3 =
     Spiral (
       SpringMajorRadius ,
       SpringMinorRadius,
       SpringHeight3 /SpringRevolutions3,
       SpringRevolutions3,
       SpringSegments3 // 5*SpringRevolutions usually is enough
       ) /* { */ rotate -90*y /* same orientation as Warp's spring */ }


#declare Springs = union {

                         object { Spring}
                         object { Spring2
                         translate SpringHeight *y
                                 }
                         object { Spring3
                         translate -SpringHeight3 *y
                                 }
                         }

                 object { Springs

	rotate 90*x
//                scale 0.02
//scale -1*z

scale <1,1,-1>

	translate  HeightOffset *z


rotate x*90
translate y* Y_Adjust                                                // 
<- Mine
rotate y*RotSpeed
                                                                      // 
<- Mine
                          pigment
                                 { color rgb <1.0, 1.0, 1.0>  }
                          finish
                                  {
                                     ambient 0.194233
                                     diffuse 0.424433
                                     brilliance 16.992
                                     phong 0.482
                                     phong_size 66.886667
                                     specular 0.129467
                                     roughness 0.1203
                                     reflection
                                     {
                                        0.13 , 0.34
                                        fresnel  off
                                        falloff  1.0
                                        exponent 1.0
                                        metallic 0.5
                                     }
                                  }

                 }




-- 

Regards
     Stephen


Post a reply to this message

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