home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Ray Tracing Box
/
RAY_CD.mdf
/
raytrace
/
_pov_dat
/
spark
/
ribcyl.inc
< prev
next >
Wrap
Text File
|
1993-03-15
|
7KB
|
178 lines
/*
* RIBCYL.INC
*
* This file declares ribbed cylinders. These cylinders have their
* length in the X axis, and are all 1 unit outside radius, 0.878 units
* inside radius, 0.939 nominal radius (the radius at each end) and
* 2 units in length, centered on <0 0 0>
*
* John Lowery
* 71075, 1401
*
*-----------------------------------------------------------------------
*
* The ribs are generated by varying the radius of a YZ circle as a
* function of X in (-1 <= x <= 1):
*
* y^2 + z^2 = K - (x^3 - x)
*
* K is the square of the nominal radius of the cylinder. The
* cubic parabola (x^3 - x) changes the radius by +/- 0.385 units.
* The relative depth of the ribs can be easily modified by changing
* the value of K, and changing the scale<> function at the end of
* the declaration of 'RibSection' to scale the nominal radius (K),
* outside radius (K + 0.385) or inside radius (K - 0.385) to the
* desired value.
*
* union { OneRibSection } is a single rib.
* union { TwoRibSection } is a double rib.
* union { FourRibSection } is a quadruple rib.
*
* These are VERY time-consuming, so each section should be bounded:
*
* object
* {
* union { FourRibSection }
* bounded_by { box {<-0.5 -1 -1><0.5 1 1>} }
* (( or ))
* bounded_by { intersection { Disk_X scale <0.5 1 1> } }
* texture<>
* scale <>
* translate<>
* }
*/
#declare RibSection =
intersection {
plane { <1.0 0.0 0.0> -1 inverse texture { color Clear } }
plane { <1.0 0.0 0.0> 1 texture { color Clear } }
quartic {
< 0.0 0.0 0.0 1.0 /* x^4 x^3y x^3z x^3 */
0.0 0.0 0.0 0.0 /* x^2y^2 x^2yz x^2y x^2z^2 */
0.0 0.0 0.0 0.0 /* x^2z x^2 xy^3 xy^2z */
0.0 0.0 0.0 0.0 /* xy^2 xyz^2 xyz xy */
0.0 0.0 0.0 -1.0 /* xz^3 xz^2 xz x */
0.0 0.0 0.0 0.0 /* y^4 y^3z y^3 y^2z^2 */
0.0 1.0 0.0 0.0 /* y^2z y^2 yz^3 yz^2 */
0.0 0.0 0.0 0.0 /* yz y z^4 z^3 */
1.0 0.0 -3.0 > /* z^2 z K */
}
scale <0.5 0.5435 0.5435> /* scale radius = sqrt(3) +/- 0.385 */
/* length = 2 to the desired values */
}
#declare OneRibSection = /* one rib section, one unit long */
union {
intersection { RibSection }
}
#declare TwoRibSection = /* two rib section, one unit long */
union {
intersection {RibSection scale <0.5 1 1> translate <-0.25 0 0> }
intersection {RibSection scale <0.5 1 1> translate < 0.25 0 0> }
}
#declare FourRibSection = /* four rib section, one unit long */
union {
intersection {RibSection scale <0.25 1 1> translate <-0.375 0 0> }
intersection {RibSection scale <0.25 1 1> translate <-0.125 0 0> }
intersection {RibSection scale <0.25 1 1> translate < 0.125 0 0> }
intersection {RibSection scale <0.25 1 1> translate < 0.375 0 0> }
}
/*
* Screw thread: generated by oscillating a YZ circle in the YZ plane
* as it is swept down the X plane. Outside diameter is
* 1 unit.
*
* To the equation for the circle (y^2 + z^2 - K = 0) is added an
* origin offset, which is dependent on the position along the X axis:
*
* (y - sin(x))^2 + (z - cos(x))^2 - K = 0
*
* expanding:
*
* y^2 + z^2 - 2y sin(x) - 2z cos(x) + sin^2(x) + cos^2(x) - K = 0
*
* since sin^2(x) + cos^2(x) = 1,
*
* y^2 + z^2 - 2y sin(x) - 2z cos(x) + 1 - K = 0
*
* Taking the taylor expansions for sin, cos, terms in the quartic
* range only:
*
* sin(x) = x - x^3/6, cos(x) = 1 - x^2/2
*
* substituting, gives:
*
* y^2 + z^2 - 2xy + .333 x^3y - 2z +x^2z + 1 - K = 0
*
* Note that since sin(x) and cos(x) move between -1 and 1, the
* square root of K must be 10 or so to provide a visually correct
* screw thread.
*
* Also, note that each quartic is only used for 1/4 turn of the
* screw (0 <= x <= 1.58 radians). This is because the approximations
* used for sin(x) and cos(x) exhibit significant errors at larger
* values, so we do it piecewise for a smoother surface.
*
* union { FourThreadSection } is a quadruple thread, one unit outside
* radius, two units long on the x axis, centered on x=0.
*
* These are VERY time-consuming, so each section should be bounded
* by a cylinder:
*
* object
* {
* union { FourThreadSection }
* bounded_by { box {<-1 -1 -1><1 1 1>} }
* (( or ))
* bounded_by { intersection { Disk_X scale <1 1 1> } }
* texture<>
* scale <>
* translate<>
* }
*/
#declare Thread =
intersection {
plane { <1.0 0.0 0.0> 0 inverse texture { color Clear } }
plane { <1.0 0.0 0.0> 1.58 texture { color Clear } }
quartic {
< 0.0 0.3333 0.0 0.0 /* x^4 x^3y x^3z x^3 */
0.0 0.0 0.0 0.0 /* x^2y^2 x^2yz x^2y x^2z^2 */
1.0 0.0 0.0 0.0 /* x^2z x^2 xy^3 xy^2z */
0.0 0.0 0.0 -2.0 /* xy^2 xyz^2 xyz xy */
0.0 0.0 0.0 0.0 /* xz^3 xz^2 xz x */
0.0 0.0 0.0 0.0 /* y^4 y^3z y^3 y^2z^2 */
0.0 1.0 0.0 0.0 /* y^2z y^2 yz^3 yz^2 */
0.0 0.0 0.0 0.0 /* yz y z^4 z^3 */
1.0 -2.0 -99.0 > /* z^2 z K */
}
scale <0.09 0.09 0.09> // 1 unit outside radius, .25 unit length
}
#declare FourThreadSection = // four thread section, two units long
// .. along x axis, centered on x=0
union {
intersection { Thread translate <-1.0 0 0> }
intersection { Thread translate <-.875 0 0> rotate <270 0 0>}
intersection { Thread translate <-.75 0 0> rotate <180 0 0> }
intersection { Thread translate <-.625 0 0> rotate < 90 0 0>}
intersection { Thread translate <-.50 0 0> }
intersection { Thread translate <-.375 0 0> rotate <270 0 0>}
intersection { Thread translate <-.25 0 0> rotate <180 0 0>}
intersection { Thread translate <-.125 0 0> rotate < 90 0 0>}
intersection { Thread translate <0 0 0> }
intersection { Thread translate <.125 0 0> rotate <270 0 0>}
intersection { Thread translate <.25 0 0> rotate <180 0 0> }
intersection { Thread translate <.375 0 0> rotate <90 0 0>}
intersection { Thread translate <.50 0 0> }
intersection { Thread translate <.625 0 0> rotate <270 0 0>}
intersection { Thread translate <.75 0 0> rotate <180 0 0> }
intersection { Thread translate <.875 0 0> rotate <90 0 0>}
}