home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 1995 January / pcw-0195.iso / polyray / dat / poly / helix.pi < prev    next >
Text File  |  1994-12-31  |  2KB  |  69 lines

  1. // Corkscrew shape - a helix is used in CSG with a cylinder to make something
  2. // very reminiscent of a drill bit.
  3. // Polyray input file: Alexander Enzmann
  4.  
  5. viewpoint {
  6.    from <0, 0, -10>
  7.    at   <0, 0, 0>
  8.    up   <0, 1, 0>
  9.    resolution 128, 128
  10.    angle 45
  11.    }
  12.  
  13. // Toss in a couple of light sources. 
  14. //light white, <-200, 100, -300>
  15. light white, < 200, 100, -300>
  16. include "..\colors.inc"
  17.  
  18. //
  19. // Approximation to the helix z = arctan(y/x).
  20. //
  21. // The helix can be approximated with an algebraic equation (kept to the
  22. // range of a quartic) with the following steps:
  23. //
  24. //    tan(z) = y/x   =>  sin(z)/cos(z) = y/x   =>
  25. //
  26. // (1) x sin(z) - y cos(z) = 0
  27. //
  28. // Using the taylor expansions for sin, cos about z = 0,
  29. //
  30. //    sin(z) = z - z^3/3! + z^5/5! - ...
  31. //    cos(z) = 1 - z^2/2! + z^6/6! - ...
  32. //
  33. // Throwing out the high order terms, the expression (1) can be written as:
  34. //
  35. //    x (z - z^3/6) - y (1 + z^2/2) = 0, or
  36. //
  37. //(2) -1/6 x z^3 + x z + 1/2 y z^2 - y = 0
  38. //
  39. //This helix (2) turns 90 degrees in the range 0 <= z <= sqrt(2)/2.  By using
  40. //scale <2 2 2>, the helix defined below turns 90 degrees in the range
  41. //0 <= z <= sqrt(2) = 1.4042.
  42.  
  43. define Helix
  44. object {
  45.      object { polynomial -(1/6) * x * z^3 + x * z + (1/2) * y * z^2 - y }
  46.    * object { box <-2, -2, 0>, <2, 2, 1.4142> }
  47.    * object { cylinder <0, 0, -0.01>, <0, 0, 1.5>, 2 }
  48.    bounding_box <-2, -2, 0>, <2, 2, 1.4142>
  49.    }
  50.  
  51. define Red_Helix Helix { shiny_red }
  52. define Green_Helix Helix { shiny_green }
  53.  
  54. define Full_Turn_Helix
  55. object {
  56.      Helix
  57.    + Helix { translate <0, 0,   sqrt(2)> rotate <0, 0, 90> }
  58.    + Helix { translate <0, 0, 2*sqrt(2)> rotate <0, 0, 180> }
  59.    + Helix { translate <0, 0, 3*sqrt(2)> rotate <0, 0, 270> }
  60.    }
  61.  
  62. object {
  63.      Full_Turn_Helix
  64.    + Full_Turn_Helix { translate <0, 0, 4*sqrt(2)> }
  65.    shiny_red
  66.    rotate <-90, 0, 0>
  67.    translate <0, -6, 5>
  68.    }
  69.