POV-Ray Raytracer Descriptions and Examples by Friedrich A. Lohmüller
Italiano Italiano
Français français
Deutsch Deutsch

overview my macro objects overview my macro objects macro "Segment_of_Torus (...)"

This shape is definded as "macro" in my include file "shapes_lo.inc":

Cylinder_Ring_Segment

Segment_of_CylinderRing


   Segment of a Cylindrical Ring
 
general syntax:
object{ Segment_of_CylinderRing (R_out, R_in, Height, Segment_Angle)
        texture{ ... ... }
      } // end of object ------------
With:
R_out = the outer radius of the cylindrical ring,
R_in = the inner radius of the cylindrical ring,
Height = the height of the ring segment,
Segment_Angle = the angle in degrees lefthanded orientated!
For Segment_Angle = 0 we get a closed ring or a tube.
For reasons of compatibility the old macro "Cylinder_Ring_Segment"
still exists - there the angle was orientated in a righthanded sense!
Beispiele:
#include "shapes_lo.inc"
// --------------------------------------------------------------------------
object{ Cylinder_Ring_Segment ( 3.75, 2.25, 0.20,-300)
        texture { Chrome_Metal
                  finish { ambient 0.1 diffuse 0.85  phong 1}
                } // end of texture
        scale <1,1,1> rotate<0,0,0> translate<0,0,0>
      } // ------------------------------------------------------------------

// --------------------------------------------------------------------------
object{ Segment_of_CylinderRing ( 1.75, 1.50, 2.00,-270)
        texture{ pigment {color White*1.1}
                 finish { ambient 0.15 diffuse 0.85 phong 1 }
               } // end of texture
      } // ------------------------------------------------------------------

// --------------------------------------------------------------------------
object{ Segment_of_CylinderRing ( 2.50, 3.00, 1.00, -80)
        texture { pigment{ color rgb< 0.7, 1, 0.0> }
                  finish { ambient 0.15 diffuse 0.75  phong 1 reflection 0.2}
                } // end of texture
      } // ------------------------------------------------------------------

// --------------------------------------------------------------------------
object{ Segment_of_CylinderRing ( 1.1, 0.80, 1.50,  0)
        texture { pigment{ color rgb< 1,0.7, 0.0> }
                  finish { ambient 0.15 diffuse 0.75  phong 1 reflection 0.2}
                } // end of texture
      } // ------------------------------------------------------------------ 


Macro in detail:

First we subtract from a cylinder with the radius R_out a smaller cylinder with the radius R_in by making an intersection of the first cylinder with the inverse of the second cylinder. Then 2 boxes rotated against another were used to cut out the wanted segment.
For this we have to consider two cases:
1. abs(Segment_Angle) <= 180 degrees (just an intersection of the torus and the two boxes) and
2. abs(Segment_Angle) > 180 degrees (an intersection of the torus and the union of the two boxes):

//--------------------------------------------------- Segment_of_CylinderRing macro
#macro  Segment_of_CylinderRing ( R_out, R_in, Height, Segment_Angle)

#local D = 0.0001; // just a little bit

 #if (Height = 0 ) #local  Height = D; #end
 #if (Height < 0 ) #local  D = -D; #end

 #if (R_out < R_in) #local X=R_out; #local R_out=R_in; #local R_in=X; #end

 #if (Segment_Angle < 0)
      #local Negativ_Flag = 1;
      #local Segment_Angle = -Segment_Angle;
 #else
      #local Negativ_Flag = 0;
 #end


 #if (Segment_Angle >= 360) #local Segment_Angle = mod (Segment_Angle, 360); #end

 intersection{
   cylinder { <0,0,0>,<0,Height,0>, R_out
            } // end of outer cylinder  ----------
   cylinder { <0,-D,0>,<0,Height+D,0>, R_in
              inverse
            } // end of inner cylinder  ----------


  #if (Segment_Angle > 0) // ------------------------------------------------------
  #if (Segment_Angle >= 180)
  union{
  #end // then use union!

   box { <-R_out+D,-D,0>,< R_out+D, Height+D, R_out+D>
         rotate<0,0,0>
       }// end of box

   box { <-R_out+D,-D,-R_out+D>,< R_out+D, Height+D,0>
         rotate<0,-Segment_Angle,0>
       }// end of box

  #if (Segment_Angle >= 180)
   } // end of union
  #end // end of union, if union is used!

 #if (Negativ_Flag = 0)  rotate<0,-Segment_Angle,0>
 scale<-1,1,-1>
  #end // of "#if (Segment_Angle > 0)" --------------------------------------------

  } // end of intersection

#end // end of macro ------------------------- end of macro Segment_of_CylinderRing -

The following images show how this macro works
(the boxes are visualizised in texture glass):

 
Cylinder_Ring_Segment 145 degrees Cylinder_Ring_Segment 215 degrees
abs(Segment_Angle) <= 180 degrees
R_out = 1.25, R_in = 0.75, Angle =-145
abs(Segment_Angle) > 180 degrees
R_out = 1.25, R_in = 0.75, Angle =-215






overview my macro objects overview my macro objects macro "Segment_of_Torus (...)"

© Friedrich A. Lohmüller, 2010
email email: (legacy email redacted)
homepage:www.f-lohmueller.de