prev index next 
Making Difficult Objects 
 POV-Ray Tips, 
 Tricks, and Techniques
Spiral / Spring Generator? 
 
Karl Manning wonders: Is there a spiral generator/include file for POV somewhere?
Specifically I want to generate some spring like objects.
 
Guy Rauscher posts a solution:
Try this bit of code:

// SPRING.POV
// creates a spring shape from spheres and cylinders
// by Guy Rauscher March 14, 1997

#include "colors.inc"
#include "textures.inc"

#default {
   pigment { color White }
   finish { Shiny }
}

camera { location <0,5,-5>
         look_at  <0,0,0> }

light_source { <5,20,-20> color White*1.5 }

#declare spring = union {
#declare N = 3 // Number of cycles about the y axis
#declare R1 = 1 // Major radius
#declare R2 = 0.15 // Minor radius
#declare H = 2 // Height
#declare P0 = <R1,0,0>
#declare T = 0.01 // Loop step. Decrease for even better results
#declare I = 0 // Loop variable
#while (I<H)
   #declare I = I + T // Increase loop variable in one step
   #declare P1 = vrotate(<R1,I,0>,<0,I/H*360*N,0>)
   sphere { P0, R2 }
   cylinder { P0, P1, R2 }
   #declare P0 = P1
#end
sphere { P0, R2 }
}

object { spring }
 

I didn't use Povray for a while because I was busy studying, but I'm pretty sure this works. It will create a spring of a major radius of R1 (distance from y axis to the extend of the spring) and a minor radius of R2 (the actual radius of the spring). The spring will start at <0,0,0> and will go up to <0,H,0>, cycling N times around the y axis.  If it seems a little bulky (unlikely, but it is made of cylinders), decrease T, which controls the distance at which another cylinder is made reaching the previous cylinder. The connections between the cylinders are connected by spheres. For more examples of this technique, see my entry to the Flight IRTC: foo.jpg.  Please comment.
 

  1