#include "metals.inc"
#include "finish.inc"

#macro negpath(tnow,thisR,F_mag)
union{
   #declare v_mag=.7*F_mag;
   #if((tnow>0)&(tnow<T_period))
      union{
         sphere{0,charge_radius pigment{color rgb <.2,.2,1>} finish{Luminous}}
         #if(showvectors=1)
            union{ //force vector
               cylinder{0,(F_mag-coneheight)*z,linewidth} 
               cone{0,coneradius,coneheight*z,0 translate (F_mag-coneheight)*z}
               text {  ttf "timesi.ttf", "F",.001, 0 translate -.25*x-.25*y 
                  scale .3  rotate y*camera_vantage_angle rotate degrees(-q1theta(tnow))*x
                  translate z*(.1+F_mag)  
               }
               pigment{color rgb <.7,.0,.0>} finish{Luminous}  scale .5
            }
            union{ //velocity vector
               cylinder{0,(v_mag-coneheight)*y,linewidth} 
               cone{0,coneradius,coneheight*y,0 translate (v_mag-coneheight)*y}
               text {  ttf "timesi.ttf", "v",.001, 0 translate -.25*x-.25*y 
                  scale .3  rotate y*camera_vantage_angle rotate degrees(-q1theta(tnow))*x
                  translate y*(.1+v_mag)  
               }
               pigment{color rgb <.1,.7,.7>} finish{Luminous}  scale .5
            }

         #end
         #if(showR=1)
            cylinder{0,thisR*z, .5*linewidth pigment{color rgb <.7,.1,.7>} finish{Luminous} translate -2*linewidth*x}
            text {  ttf "timesi.ttf", "R",.001, 0 translate -.25*x-.25*y 
               scale .125  rotate y*camera_vantage_angle rotate degrees(-q1theta(tnow))*x
               translate z*(.1+thisR)  pigment{color rgb <.7,.1,.7>} finish{Luminous} 
            }
         #end
         translate -thisR*z rotate degrees(q1theta(tnow))*x translate thisR*z
      }
      #declare track_dt= T_period/100;
      #declare track_tnow= tnow;
      #declare tp1=thisR*<0,sin(q1theta(track_tnow)),(1-cos(q1theta(track_tnow)))>;
      #declare tpR1=.25*charge_radius; 
      #while(track_tnow>0)
         #declare track_tnow=track_tnow-track_dt;
         #declare tp2=thisR*<0,sin(q1theta(track_tnow)),(1-cos(q1theta(track_tnow)))>;
         #declare tpR2=.9*tpR1; 
         union{
            sphere{tp1,tpR1 } 
            cone{tp1,tpR1,tp2,tpR2}
            pigment{color rgb .8*<.5,.5,1>} finish{Luminous}
         }
         #declare tp1=tp2;
         #declare tpR1=tpR2;
          
      #end
   #end


}
#end   


#macro pospath(tnow,thisR,F_mag)
union{
   #declare v_mag=.7*F_mag;
   #if(tnow>0&(tnow<T_period))
      union{
         sphere{0,charge_radius pigment{color rgb <1,.2,.2>} finish{Luminous}}
         #if(showvectors=1)
            union{ //force vector
               cylinder{0,-(F_mag-coneheight)*z,linewidth} 
               cone{0,coneradius,-coneheight*z,0 translate -(F_mag-coneheight)*z}
               text {  ttf "timesi.ttf", "F",.001, 0 translate -.25*x-.25*y 
                  scale .3  rotate y*camera_vantage_angle rotate degrees(q1theta(tnow))*x
                  translate -z*(.1+F_mag)  
               }
               pigment{color rgb <.7,.0,.0>} finish{Luminous}  scale .5
            }
            union{ //velocity vector
               cylinder{0,(v_mag-coneheight)*y,linewidth} 
               cone{0,coneradius,coneheight*y,0 translate (v_mag-coneheight)*y}
               text {  ttf "timesi.ttf", "v",.001, 0 translate -.25*x-.25*y 
                  scale .3  rotate y*camera_vantage_angle rotate degrees(q1theta(tnow))*x
                  translate y*(.1+v_mag)  
               }
               pigment{color rgb <.1,.7,.7>} finish{Luminous}  scale .5
            }

         #end
         #if(showR=1)
            cylinder{0,-thisR*z, .5*linewidth pigment{color rgb <.7,.1,.7>} finish{Luminous} translate -2*linewidth*x}
            text {  ttf "timesi.ttf", "R",.001, 0 translate -.25*x-.25*y 
               scale .125  rotate y*camera_vantage_angle rotate degrees(q1theta(tnow))*x
               translate -z*(.1+thisR)  pigment{color rgb <.7,.1,.7>} finish{Luminous} 
            }
         #end
         translate thisR*z rotate degrees(-q1theta(tnow))*x translate -thisR*z
      }
      #declare track_dt= T_period/100;
      #declare track_tnow= tnow;
      #declare tp1=thisR*<0,sin(q1theta(track_tnow)),-(1-cos(q1theta(track_tnow)))>;
      #declare tpR1=.25*charge_radius; 
      #while(track_tnow>0)
         #declare track_tnow=track_tnow-track_dt;
         #declare tp2=thisR*<0,sin(q1theta(track_tnow)),-(1-cos(q1theta(track_tnow)))>;
         #declare tpR2=.9*tpR1; 
         union{
            sphere{tp1,tpR1 } 
            cone{tp1,tpR1,tp2,tpR2}
            pigment{color rgb .8*<1,.5,.5>} finish{Luminous}
         }
         #declare tp1=tp2;
         #declare tpR1=tpR2;
          
      #end
   #end

}
#end
#macro pospath2(tnow,thisR,F_mag,theta)
union{
   #declare v_mag=.7*F_mag;
   #if(tnow>0&(tnow<T_period))
      union{
         sphere{0,charge_radius pigment{color rgb <1,.2,.2>} finish{Luminous}}
         #if(showvectors=1)
            union{ //force vector
               cylinder{0,-(F_mag-coneheight)*z,linewidth} 
               cone{0,coneradius,-coneheight*z,0 translate -(F_mag-coneheight)*z}
               text {  ttf "timesi.ttf", "F",.001, 0 translate -.25*x-.25*y 
                  scale .3  rotate y*camera_vantage_angle rotate degrees(q1theta(tnow))*x
                  translate -z*(.1+F_mag)  
               }
               pigment{color rgb <.7,.0,.0>} finish{Luminous}  scale .5
            }
            union{ //velocity vector
               cylinder{0,(v_mag-coneheight)*y,linewidth} 
               cone{0,coneradius,coneheight*y,0 translate (v_mag-coneheight)*y}
               text {  ttf "timesi.ttf", "v",.001, 0 translate -.25*x-.25*y 
                  scale .3  rotate y*camera_vantage_angle rotate degrees(q1theta(tnow))*x
                  translate y*(.1+v_mag)  
               }
               pigment{color rgb <.1,.7,.7>} finish{Luminous}  scale .5
            }

         #end
         #if(showR=1)
            cylinder{0,-thisR*z, .5*linewidth pigment{color rgb <.7,.1,.7>} finish{Luminous} translate -2*linewidth*x}
            text {  ttf "timesi.ttf", "R",.001, 0 translate -.25*x-.25*y 
               scale .125  rotate y*camera_vantage_angle rotate degrees(q1theta(tnow))*x
               translate -z*(.1+thisR)  pigment{color rgb <.7,.1,.7>} finish{Luminous} 
            }
         #end
         translate thisR*z rotate degrees(-q1theta(tnow))*x translate -thisR*z
      }
      #declare track_dt= T_period/100;
      #declare track_tnow= tnow;
      #declare tp1=thisR*<0,sin(q1theta(track_tnow)),-(1-cos(q1theta(track_tnow)))>;
      #declare tpR1=.25*charge_radius; 
      #while(track_tnow>0)
         #declare track_tnow=track_tnow-track_dt;
         #declare tp2=thisR*<0,sin(q1theta(track_tnow)),-(1-cos(q1theta(track_tnow)))>;
         #declare tpR2=.9*tpR1; 
         union{
            sphere{tp1,tpR1 } 
            cone{tp1,tpR1,tp2,tpR2}
            pigment{color rgb .8*<1,.5,.5>} finish{Luminous}
         }
         #declare tp1=tp2;
         #declare tpR1=tpR2;
          
      #end
   #end

}
#end
