// "BlockBolt3.pov"
//  Block of laminations, windings, and coating
//  KHL 2017-Dec-29
//
#version 3.7;
global_settings{ assumed_gamma 1.0 }

#default{ finish{ ambient 0.1 diffuse 0.9 }} 
#include "colors.inc"
#include "textures.inc"

#declare COIL=1 ;    // draw the coil
#declare CORE=1 ;    // draw the core
#declare DIAM=1 ;    // draw the diamond coating

// camera setup -------------------------------------------------------------
#declare Camera_Location =  <4.5  , 2.0 ,-4.0> ;  // diagonal view
#declare Camera_Look_At  =  < 0.05 , 0.00 , -0.35> ;
#declare Camera_Angle    =  32 ;

// camera and lights -------------------------------------------------------
camera{ // ultra_wide_angle // orthographic 
        location Camera_Location
        right    x*image_width/image_height
        angle    Camera_Angle
        look_at  Camera_Look_At
      }

// sun and "camera flash" -----
// light_source{< 500,1500,-2500> color rgb<1,1,1>*0.9}                // sun
light_source{< 500,1500,-250> color rgb<1,1,1>*0.9}                // sun
light_source{ Camera_Location  color rgb<0.9,0.9,1>*0.0 shadowless}// flash

sky_sphere{ pigment{ color rgb<1,1,1> } }

#include "math.inc" 
#include "shapes3.inc"

#local BWR = 0.008 ;  // Wire diameter
#local BWX = 0.50  ;  // rectangular loop depth: min 2*WR (pitch)
#local BWY = 0.50  ;  // rectangular loop height
#local BWZ = 0.06  ;  // loop spacing
#local BWL = 66    ;  // number of loops
#local LLEN = 0.5*BWL*BWZ ;

#local LAM  = 0.017 ;  // lamination thickness
#local LAMG = 0.005 ;  // lamination gap
#local DY = LAM+LAMG ; // lamination stack

#local BWT = 0.5*BWZ*(BWL-0) ; // end of magnet core (extended)

// Winding_Loop macro: A rectangular coil of wire ---------------------------

#macro Winding_Loop(  WR_    , // 0.03; // Wire radius
                      WX_    , // 0.50; // X width
                      WY_    , // 0.20; // Y width
                      WZ_    , // 0.10; // Loop spacing
                      Loops_ , // 20  ;
                    ) // end of loop parameters

#local WR    = WR_          ; // Wire radius
#local WZ    = WZ_          ; // Loop Z spacing: min 2*WR  (pitch)
#local WX    = 0.5*WX_+WR_  ; // Loop X width
#local WY    = 0.5*WY_+WR_  ; // Loop Y width
#local Loops = Loops_       ; // Integer

#local RectLoop = 
union{ 
       sphere{   < WX, WY,0>,             WR  }
       cylinder{ < WX, WY,0>,< WX,-WY,0>, WR  } 
       sphere{   < WX,-WY,0>,             WR  }
       cylinder{ < WX,-WY,0>,<-WX,-WY,0>, WR  } 
       sphere{   <-WX,-WY,0>,             WR  }
       cylinder{ <-WX,-WY,0>,<-WX, WY,0>, WR  } 
       sphere{   <-WX, WY,0>,             WR  }
       cylinder{ <-WX, WY,0>,< WX, WY,0>, WR  } 
}
// end of RectLoop union ---

// Stack of Nr loops in Z direction ------------------------------
union{ 
 #local  NZ = 0.5*(Loops-1.0)*WZ ;
 #local  DZ = -NZ;             // start
 #while (DZ <= NZ )            // loop
   object{ RectLoop translate<0, 0, DZ > }
   #local DZ = DZ + WZ; // next DZ
 #end // end of DZ loop

} 

#end  // --- end of Winding_Loop macro --------------------------------------

// NOW, DRAW THE COIL

// Winding loop group instance ----------------------------------

#if( COIL )
object{ Winding_Loop( BWR, // Wire radius
                      BWX, // rectangular loop X width
                      BWY, // rectangular loop Y width
                      BWZ, // loop spacing: min 2*WR (pitch)
                      BWL  // number of loops
                      )  

        // approximate copper color
        texture{ pigment{ color rgb< 0.85, 0.37, 0.15>*0.59 }
                 finish { phong 1.0 specular 0.3 reflection{ 0.25 metallic 0.5 } }
               } // end of copper texture

        // translate and rotate 
        // rotate<0,0,0> 
        // translate<0,0,0>
      } // end of Winding_Loop object instance

#end // COIL
// End of Winding Loop group instance ----------


// laminated iron core instance ---------------------------
#if( CORE )

object{
   union {
      #local WX= 0.5*BWX ;
      #local WY= 0.5*BWY ;
      #local LY=0.5*DY-WY;
      #local LAY = LAM/2 ;

      #while ( LY < WY )            // loop
        box{ <-WX,-LAY,-LLEN>, <WX,LAY,LLEN> translate<0,LY,0> }
        #local LY = LY + DY ;
      #end // end LY loop
   }

   // approximate iron color
   texture{ pigment{ color rgb<1,1,1>*0.3 }
            finish{ phong 0.0 specular 0.2 }
   } // end of iron texture
} 
#end // CORE
// end of iron core instance -------------------

// amorphous diamond coating instance ----------------------
#if( DIAM )

#local  BMX = -0.5*BWX ;
#local  BMY = -0.5*BWY ;
#local  BMZ =    -LLEN ;
#local  BPX =  0.5*BWX ;
#local  BPY =  0.5*BWY ;
#local  BPZ =     LLEN ;
#local  BR  =  3.0*BWR ;

merge{ 
  box { <BMX-BR,BMY,BMZ>,<BPX+BR,BPY,BPZ>  material{M_Glass} }
  box { <BMX,BMY-BR,BMZ>,<BPX,BPY+BR,BPZ>  material{M_Glass} }
  box { <BMX,BMY,BMZ-BR>,<BPX,BPY,BPZ+BR>  material{M_Glass} }
  cylinder{ <BMX,BMY,BMZ>,<BPX,BMY,BMZ>,BR material{M_Glass} }
  cylinder{ <BMX,BMY,BPZ>,<BPX,BMY,BPZ>,BR material{M_Glass} }
  cylinder{ <BMX,BPY,BMZ>,<BPX,BPY,BMZ>,BR material{M_Glass} }
  cylinder{ <BMX,BPY,BPZ>,<BPX,BPY,BPZ>,BR material{M_Glass} }
  cylinder{ <BMX,BMY,BMZ>,<BMX,BPY,BMZ>,BR material{M_Glass} }
  cylinder{ <BMX,BMY,BPZ>,<BMX,BPY,BPZ>,BR material{M_Glass} }
  cylinder{ <BPX,BMY,BMZ>,<BPX,BPY,BMZ>,BR material{M_Glass} }
  cylinder{ <BPX,BMY,BPZ>,<BPX,BPY,BPZ>,BR material{M_Glass} }
  cylinder{ <BMX,BMY,BMZ>,<BMX,BMY,BPZ>,BR material{M_Glass} }
  cylinder{ <BPX,BMY,BMZ>,<BPX,BMY,BPZ>,BR material{M_Glass} }
  cylinder{ <BMX,BPY,BMZ>,<BMX,BPY,BPZ>,BR material{M_Glass} }
  cylinder{ <BPX,BPY,BMZ>,<BPX,BPY,BPZ>,BR material{M_Glass} }
  sphere{   <BMX,BMY,BMZ>,              BR material{M_Glass} }
  sphere{   <BMX,BMY,BPZ>,              BR material{M_Glass} }
  sphere{   <BMX,BPY,BMZ>,              BR material{M_Glass} }
  sphere{   <BMX,BPY,BPZ>,              BR material{M_Glass} }
  sphere{   <BPX,BMY,BMZ>,              BR material{M_Glass} }
  sphere{   <BPX,BMY,BPZ>,              BR material{M_Glass} }
  sphere{   <BPX,BPY,BMZ>,              BR material{M_Glass} }
  sphere{   <BPX,BPY,BPZ>,              BR material{M_Glass} }
} 

#end // DIAM
// end of amorphous diamond coating instance --------------

// End of .pov file ----------------------------


