home *** CD-ROM | disk | FTP | other *** search
/ Mega A/V / mega_av.zip / mega_av / GRAPHUTL / POVSCN.ZIP / MATH.ZIP / HELIX.POV < prev    next >
Text File  |  1992-07-03  |  3KB  |  155 lines

  1. // Persistence Of Vision raytracer version 1.0 sample file.
  2.  
  3. // Sample quartic { file
  4. // by Alexander Enzmann
  5.  
  6. #include "shapes.inc"
  7. #include "colors.inc"
  8. #include "textures.inc"
  9. #include "shapesq.inc"
  10.  
  11. /*
  12.    Approximation to the helix z = arctan(y/x).
  13.  
  14.    The helix can be approximated with an algebraic equation (kept to the
  15.    range of a quartic) with the following steps:
  16.  
  17.       tan(z) = y/x   =>  sin(z)/cos(z) = y/x   =>
  18.  
  19.    (1) x sin(z) - y cos(z) = 0
  20.  
  21.    Using the taylor expansions for sin, cos about z = 0,
  22.  
  23.       sin(z) = z - z^3/3! + z^5/5! - ...
  24.       cos(z) = 1 - z^2/2! + z^6/6! - ...
  25.  
  26.    Throwing out the high order terms, the expression (1) can be written as:
  27.  
  28.       x (z - z^3/6) - y (1 + z^2/2) = 0, or
  29.  
  30.   (2) -1/6 x z^3 + x z + 1/2 y z^2 - y = 0
  31.  
  32.   This helix (2) turns 90 degrees in the range 0 <= z <= sqrt(2)/2.  By using
  33.   scale <2 2 2>, the helix defined below turns 90 degrees in the range
  34.   0 <= z <= sqrt(2) = 1.4042.
  35. */
  36.  
  37. #declare Red_Helix =
  38. object { Helix
  39.    texture {
  40.       /* gradient <0 1 0>
  41.         color_map
  42.            [0 1.001 color red 1 green 0 blue 0 color red 0 green 1 blue 0]
  43.         end_color_map */
  44.       color red 1 green 0 blue 0
  45.       /* scale <1 1.4142 1> */
  46.       phong 1.0
  47.    }
  48.    bounded_by {
  49.       sphere { <0 0 0> 2.5 }
  50.       quadric { Cylinder_Z scale <2.0 2.0 2.0> }
  51.    }
  52. }
  53.  
  54. #declare Green_Helix =
  55. object { Helix
  56.    texture {
  57.       /*gradient <0 1 0>
  58.        color_map
  59.           [0 1.001 color red 0 green 1 blue 0 color red 1 green 0 blue 0]
  60.        end_color_map */
  61.       color red 0 green 1 blue 0
  62.       /* scale <1 1.4142 1> */
  63.       phong 1.0
  64.    }
  65.    bounded_by {
  66.       sphere { <0 0 0> 2.5 }
  67.       quadric { Cylinder_Z scale <2.0 2.0 2.0> }
  68.    }
  69. }
  70.  
  71. // Glue a bunch of pieces together to make one long helix. 
  72.  
  73. object { Green_Helix
  74.    translate <0 0 -4.2426>
  75.    rotate <0 0 160>
  76.    rotate <-90 0 0>
  77.    translate <0 -2 5>
  78. }
  79.  
  80. object { Red_Helix
  81.    translate <0 0 -2.8284>
  82.    rotate <0 0 70>
  83.    rotate <-90 0 0>
  84.    translate <0 -2 5>
  85. }
  86.  
  87. object { Green_Helix
  88.    translate <0 0 -1.4142>
  89.    rotate <0 0 160>
  90.    rotate <-90 0 0>
  91.    translate <0 -2 5>
  92. }
  93.  
  94. object { Red_Helix
  95.    rotate <0 0 70>
  96.    rotate <-90 0 0>
  97.    translate <0 -2 5>
  98. }
  99.  
  100. object { Green_Helix
  101.    translate <0 0 1.4142>
  102.    rotate <0 0 160>
  103.    rotate <-90 0 0>
  104.    translate <0 -2 5>
  105. }
  106.  
  107. object { Red_Helix
  108.    translate <0 0 2.8284>
  109.    rotate <0 0 70>
  110.    rotate <-90 0 0>
  111.    translate <0 -2 5>
  112. }
  113.  
  114. object { Green_Helix
  115.    translate <0 0 4.2426>
  116.    rotate <0 0 160>
  117.    rotate <-90 0 0>
  118.    translate <0 -2 5>
  119. }
  120.  
  121. object { Red_Helix
  122.    translate <0 0 5.6569>
  123.    rotate <0 0 70>
  124.    rotate <-90 0 0>
  125.    translate <0 -2 5>
  126. }
  127.  
  128. object { Green_Helix
  129.    translate <0 0 7.0711>
  130.    rotate <0 0 160>
  131.    rotate <-90 0 0>
  132.    translate <0 -2 5>
  133. }
  134.  
  135.  
  136. camera {
  137.    location <0.0  0.0 -10.0>
  138.    direction <0.0 0.0 1.0>
  139.    up        <0.0 1.0 0.0>
  140.    right     <1.333 0.0 0.0>
  141. }
  142.  
  143. // Toss in a couple of light sources. 
  144. object {
  145.    light_source { <200 100 -300>
  146.       colour red 1.0 green 1.0 blue 1.0
  147.    }
  148. }
  149.  
  150. object {
  151.    light_source { <-200 100 -300>
  152.       colour red 1.0 green 1.0 blue 1.0
  153.    }
  154. }
  155.