home *** CD-ROM | disk | FTP | other *** search
/ Ray Tracing Box / RAY_CD.mdf / raytrace / _pov_dat / spark / ribcyl.inc < prev    next >
Text File  |  1993-03-15  |  7KB  |  178 lines

  1. /*
  2.  *  RIBCYL.INC
  3.  *
  4.  *  This file declares ribbed cylinders.  These cylinders have their
  5.  *  length in the X axis, and are all 1 unit outside radius, 0.878 units
  6.  *  inside radius, 0.939 nominal radius (the radius at each end) and 
  7.  *  2 units in length, centered on <0 0 0>
  8.  *
  9.  *  John Lowery
  10.  *  71075, 1401
  11.  *
  12.  *-----------------------------------------------------------------------
  13.  *
  14.  *  The ribs are generated by varying the radius of a YZ circle as a
  15.  *  function of X in (-1 <= x <= 1):  
  16.  *
  17.  *      y^2 + z^2 = K - (x^3 - x)
  18.  *
  19.  *  K is the square of the nominal radius of the cylinder.  The
  20.  *  cubic parabola (x^3 - x) changes the radius by +/- 0.385 units.
  21.  *  The relative depth of the ribs can be easily modified by changing 
  22.  *  the value of K, and changing the scale<> function at the end of
  23.  *  the declaration of 'RibSection' to scale the nominal radius (K),
  24.  *  outside radius (K + 0.385) or inside radius (K - 0.385) to the 
  25.  *  desired value.
  26.  * 
  27.  *  union { OneRibSection }  is a single rib.
  28.  *  union { TwoRibSection }  is a double rib.
  29.  *  union { FourRibSection } is a quadruple rib.
  30.  *
  31.  *  These are VERY time-consuming, so each section should be bounded:
  32.  *
  33.  *  object
  34.  *  {
  35.  *      union { FourRibSection }
  36.  *      bounded_by { box {<-0.5 -1 -1><0.5 1 1>} }
  37.  *      (( or ))
  38.  *      bounded_by { intersection { Disk_X  scale <0.5 1 1> } }
  39.  *      texture<>
  40.  *      scale <>
  41.  *      translate<>
  42.  *  }
  43.  */
  44.  
  45.  
  46. #declare RibSection =
  47.       intersection {
  48.          plane { <1.0 0.0 0.0> -1 inverse texture { color Clear } }
  49.          plane { <1.0 0.0 0.0>  1         texture { color Clear } }
  50.          quartic {
  51.          <  0.0     0.0     0.0     1.0     /* x^4     x^3y    x^3z    x^3    */
  52.             0.0     0.0     0.0     0.0     /* x^2y^2  x^2yz   x^2y    x^2z^2 */
  53.             0.0     0.0     0.0     0.0     /* x^2z    x^2     xy^3    xy^2z  */
  54.             0.0     0.0     0.0     0.0     /* xy^2    xyz^2   xyz     xy     */
  55.             0.0     0.0     0.0     -1.0    /* xz^3    xz^2    xz      x      */
  56.             0.0     0.0     0.0     0.0     /* y^4     y^3z    y^3     y^2z^2 */
  57.             0.0     1.0     0.0     0.0     /* y^2z    y^2     yz^3    yz^2   */
  58.             0.0     0.0     0.0     0.0     /* yz      y       z^4     z^3    */
  59.             1.0     0.0     -3.0 >          /* z^2     z       K              */
  60.          }
  61.          scale <0.5 0.5435 0.5435>  /* scale radius = sqrt(3) +/- 0.385  */
  62.                                     /* length = 2 to the desired values      */
  63.       }
  64.  
  65.  
  66. #declare OneRibSection =    /* one rib section, one unit long */
  67. union {
  68.    intersection { RibSection }
  69. }
  70.  
  71. #declare TwoRibSection =    /* two rib section, one unit long */
  72. union {
  73.    intersection {RibSection scale <0.5 1 1> translate <-0.25 0 0> }
  74.    intersection {RibSection scale <0.5 1 1> translate < 0.25 0 0> }
  75. }
  76.  
  77. #declare FourRibSection =   /* four rib section, one unit long */
  78. union {
  79.    intersection {RibSection scale <0.25 1 1> translate <-0.375 0 0> }
  80.    intersection {RibSection scale <0.25 1 1> translate <-0.125 0 0> }
  81.    intersection {RibSection scale <0.25 1 1> translate < 0.125 0 0> }
  82.    intersection {RibSection scale <0.25 1 1> translate < 0.375 0 0> }
  83. }
  84.  
  85. /*
  86.  *  Screw thread:  generated by oscillating a YZ circle in the YZ plane
  87.  *                 as it is swept down the X plane.  Outside diameter is
  88.  *                 1 unit. 
  89.  *
  90.  *  To the equation for the circle (y^2 + z^2 - K = 0) is added an 
  91.  *  origin offset, which is dependent on the position along the X axis:
  92.  *
  93.  *  (y - sin(x))^2 + (z - cos(x))^2 - K = 0
  94.  *  
  95.  *  expanding:
  96.  *
  97.  *  y^2 + z^2 - 2y sin(x) - 2z cos(x) + sin^2(x) + cos^2(x) - K = 0
  98.  *
  99.  *  since  sin^2(x) + cos^2(x) = 1, 
  100.  *
  101.  *  y^2 + z^2 - 2y sin(x) - 2z cos(x) + 1 - K = 0
  102.  *
  103.  *  Taking the taylor expansions for sin, cos, terms in the quartic
  104.  *  range only:
  105.  *
  106.  *  sin(x) = x - x^3/6,   cos(x) = 1 - x^2/2
  107.  *
  108.  *  substituting, gives:
  109.  *
  110.  *  y^2 + z^2 - 2xy + .333 x^3y - 2z +x^2z + 1 - K = 0
  111.  *
  112.  *  Note that since sin(x) and cos(x) move between -1 and 1, the
  113.  *  square root of K must be 10 or so to provide a visually correct
  114.  *  screw thread.
  115.  *
  116.  *  Also, note that each quartic is only used for 1/4 turn of the
  117.  *  screw (0 <= x <= 1.58 radians).  This is because the approximations
  118.  *  used for sin(x) and cos(x) exhibit significant errors at larger
  119.  *  values, so we do it piecewise for a smoother surface.
  120.  *
  121.  *  union { FourThreadSection } is a quadruple thread, one unit outside
  122.  *  radius, two units long on the x axis, centered on x=0.
  123.  *
  124.  *  These are VERY time-consuming, so each section should be bounded
  125.  *  by a cylinder:
  126.  *
  127.  *  object
  128.  *  {
  129.  *      union { FourThreadSection }
  130.  *      bounded_by { box {<-1 -1 -1><1 1 1>} }
  131.  *      (( or ))
  132.  *      bounded_by { intersection { Disk_X  scale <1 1 1> } }
  133.  *      texture<>
  134.  *      scale <>
  135.  *      translate<>
  136.  *  }
  137.  */
  138.  
  139. #declare Thread = 
  140.       intersection {
  141.            plane { <1.0 0.0 0.0> 0 inverse texture { color Clear } }
  142.            plane { <1.0 0.0 0.0> 1.58      texture { color Clear } }
  143.          quartic {
  144.          <  0.0     0.3333  0.0     0.0     /* x^4     x^3y    x^3z    x^3    */
  145.             0.0     0.0     0.0     0.0     /* x^2y^2  x^2yz   x^2y    x^2z^2 */
  146.             1.0     0.0     0.0     0.0     /* x^2z    x^2     xy^3    xy^2z  */
  147.             0.0     0.0     0.0     -2.0    /* xy^2    xyz^2   xyz     xy     */
  148.             0.0     0.0     0.0     0.0     /* xz^3    xz^2    xz      x      */
  149.             0.0     0.0     0.0     0.0     /* y^4     y^3z    y^3     y^2z^2 */
  150.             0.0     1.0     0.0     0.0     /* y^2z    y^2     yz^3    yz^2   */
  151.             0.0     0.0     0.0     0.0     /* yz      y       z^4     z^3    */
  152.             1.0     -2.0    -99.0 >         /* z^2     z       K              */
  153.          }
  154.          scale <0.09 0.09 0.09>   // 1 unit outside radius, .25 unit length
  155.       }
  156.  
  157. #declare FourThreadSection =   // four thread section, two units long
  158.                                // .. along x axis, centered on x=0
  159.    union {
  160.       intersection { Thread translate <-1.0 0 0> }
  161.       intersection { Thread translate <-.875 0 0> rotate <270 0 0>}
  162.       intersection { Thread translate <-.75 0 0> rotate <180 0 0> }
  163.       intersection { Thread translate <-.625 0 0> rotate < 90 0 0>}
  164.       intersection { Thread translate <-.50 0 0> }
  165.       intersection { Thread translate <-.375 0 0> rotate <270 0 0>}
  166.       intersection { Thread translate <-.25 0 0>  rotate <180 0 0>}
  167.       intersection { Thread translate <-.125 0 0> rotate < 90 0 0>}
  168.       intersection { Thread translate <0 0 0>    }
  169.       intersection { Thread translate <.125 0 0>  rotate <270 0 0>}
  170.       intersection { Thread translate <.25 0 0> rotate <180 0 0> }
  171.       intersection { Thread translate <.375 0 0> rotate <90 0 0>}
  172.       intersection { Thread translate <.50 0 0>  }
  173.       intersection { Thread translate <.625 0 0> rotate <270 0 0>}
  174.       intersection { Thread translate <.75 0 0> rotate <180 0 0> }
  175.       intersection { Thread translate <.875 0 0> rotate <90 0 0>}
  176.    }   
  177.  
  178.