Descriptions and Examples for the POV-Ray Raytracer by Friedrich A. Lohmüller
    POV-Ray Examples - How To Make Objects for POV-Ray
Italiano Italiano
Français français
Deutsch Deutsch

Home
- POV-Ray Tutorial
  - POV-Ray Examples
   Index of Content
  - Geometry
  - Architecture
  - Engineering
    - Ladder
    - Pylons
    - Railing
    - Bridge
    - Tubes
    - Tube Fork
    - Tube Stopcock
    - Chain
    - Coil of Wire
    - Torpedo
    - Cruise Missile
    - Rocket
    - Wheel
    - Truck
    - Propeller
    - Airplanes
    - Canoe
    - Guitar Body
    - 7-Segment Display
    - Ribbon Cable
    - Cable Harness
                                       
Wheel

Wheel with Spokes
- with and without a #while loop -

A example for the using of "#while" loop
Objects: "torus", "cylinder", "sphere".
Methods: "union", "#declare", "#while loop".

a) Without while-Loop

 ...
#declare Number_of_spokes = 12;
#declare W = 360/Number_of_spokes;
//------------------------------------ wheel --
union{
torus{0.9,0.20 rotate<90,0,0>
         texture{Rim_tex}} // rim
torus{1.0,0.25 rotate<90,0,0>
         texture{Tiretex}} // tire
 cylinder{<0,0,-0.10>,<0,0, 0.10>,0.20
         texture{Hub_tex}} // hub
 cylinder{<0,0,-0.12>,<0,0, 0.12>,0.15
         texture{Hub_tex}} // hub
//------------- without #while loop: -------<<1 
union{
 cylinder{<0,0,0>,<1,0,0>,0.05 rotate<0,0, 0*W>}
 cylinder{<0,0,0>,<1,0,0>,0.05 rotate<0,0, 1*W>}
 cylinder{<0,0,0>,<1,0,0>,0.05 rotate<0,0, 2*W>}
 cylinder{<0,0,0>,<1,0,0>,0.05 rotate<0,0, 3*W>}
 cylinder{<0,0,0>,<1,0,0>,0.05 rotate<0,0, 4*W>}
 cylinder{<0,0,0>,<1,0,0>,0.05 rotate<0,0, 5*W>}
 cylinder{<0,0,0>,<1,0,0>,0.05 rotate<0,0, 6*W>}
 cylinder{<0,0,0>,<1,0,0>,0.05 rotate<0,0, 7*W>}
 cylinder{<0,0,0>,<1,0,0>,0.05 rotate<0,0, 8*W>}
 cylinder{<0,0,0>,<1,0,0>,0.05 rotate<0,0, 9*W>}
 cylinder{<0,0,0>,<1,0,0>,0.05 rotate<0,0,10*W>}
 cylinder{<0,0,0>,<1,0,0>,0.05 rotate<0,0,11*W>}
 texture{Spoke_tex}
 }
//----------------------------------------- <<2 
translate<0,1.25,0>
rotate<0,0,0>} // end of union
//----------------------------------------- end  
Example while loop

Instead of many detailed single statements which change only little, we can use in these cases the loop technologie. This technology does not only reduce the work of writing the scenery file (sure: with "cut and paste" no big problem!), but it allows also to change the values for the number of elements and the step value very easy.

b) With while-Loop

 ...
//or from <<1  until <<2
 // --- with while loop ----------- >>1 
#declare Nr = 0;
#declare EndNr = Number_of_spokes;

#while ( Nr < EndNr )
  cylinder {<-1,0,0>,<1,0,0>, 0.05
            rotate<0,0,360/EndNr*Nr>
            texture{Spoke_tex}}
  #declare Nr = Nr +1;
#end // --------------------------- >>2 
...
Example while loop
Click here for the complete
scene description for POV-Ray:
"wheel_1.txt" or "wheel_1.pov"

POV-Ray uses as loop the while-loop. Whether the part between "#while"-statement and the according "#end"-statement will be executed or not is decided according the conditions inside of the round brackets behind the "#while"-statement. This is decided before the statements of this parts are executed.
This is a so-called "pre-checked loop" - well known from many programming languages. The also well known statement "repeat ... until" for a so-called "post-checked loop" does not exist in POV-Ray until now. This is not a big problem because it is possible to transform every loop of one kind to a loop of the other kind just by transforming the conditions of the loop.

With while-loops also the placing of many elements
is no problem:

Example while loop
The scene description for POV-Ray:
"wheel_2.txt" or "wheel_2.pov"
top
© Friedrich A. Lohmüller, 2009
www.f-lohmueller.de