#version 3.7; // Bill Walker "Bald Eagle" March 2017 global_settings{ assumed_gamma 1.0 } #include "colors.inc" #include "functions.inc" #include "math.inc" #include "shapes.inc" #include "shapes2.inc" #include "shapes3.inc" #include "textures.inc" #include "transforms.inc" light_source { <0, 150, 0> color rgb <1, 1, 1>} plane {y, 0 pigment {White}} //######################################################################################################### #declare Layout = false; //######################################################################################################### #declare T1 = 0.01; // Line widths #declare T2 = 0.005; #declare MarkerCircle = 0.012; #declare Teeth = 48; #declare N = Teeth; // Number of teeth on gear (N) #declare Pitch = 24; #declare P = Pitch; // Gear pitch (P) #declare Addendum = 1/P; #declare A = Addendum; #declare RootCircle = (Teeth-2)/Pitch; #declare RD = RootCircle; // Root circle diameter (RD) #declare PitchCircle = Teeth/Pitch; #declare D = PitchCircle; // Pitch circle diameter (D) //#declare OutsideCircle= (Teeth+2)/Pitch; #declare OD = OutsideCircle; // Outside circle diameter (OD) #declare OutsideCircle = D+(2*A); #declare OD = OutsideCircle; // Outside circle diameter (OD) #declare ClearanceCircle = RootCircle*0.98; #declare Hub = 0.75*RootCircle; #declare Hole = 0.125; #declare Camera1 = camera { location <0, 4.5, -0.01> //right x*image_width/image_height look_at <0, 0, 0>} #declare Camera2 = camera { location //right x*image_width/image_height look_at } camera {Camera1} // Center and tangent markers #if (Layout = true) torus {ClearanceCircle, T2 translate <0, T1, 0> texture {pigment {color Gray70} finish {phong 0.0}} } // RootCircle Circle torus {RootCircle, T2 translate <0, T1, 0> texture {pigment {color Gray50} finish {phong 0.0}} } // RootCircle Circle torus {PitchCircle, T2 translate <0, T1, 0> texture {pigment {color Red} finish {phong 0.0}} } // PitchCircle Circle torus {OutsideCircle, T2 translate <0, T1, 0> texture {pigment {color Green} finish {phong 0.0}} } // OutsideCircle Circle cylinder {<-OutsideCircle, T1, 0>, T2 texture {pigment {color Black} finish {phong 0.0}} } cylinder {<0, T1, -OutsideCircle>, <0, T1, OutsideCircle> T2 texture {pigment {color Black} finish {phong 0.0}} } cylinder {<-OutsideCircle*2, T1, RootCircle>, T2 texture {pigment {color Black} finish {phong 0.0}} } #end #declare CircularThicknessAngle = (360/N)*0.5; // Circular Thickness Angle 0.5 because teeth AND spaces #declare Degrees = 90; // Degrees to rotate through involute #declare Radians = Degrees * pi/180; // Radians to rotate through involute #declare AngularSpacing = (360/Teeth); // How many degrees to rotate involute curves for next tooth //##################################################################################### #declare XImageSize = 1024; #declare YImageSize = 768; #ifndef (SVG_File) #fopen SVG_File "InvoluteGear.svg" write #end // Write svg file header // #write (SVG_File, "") #write (SVG_File, "\n") // Line break #write (SVG_File, "") // SVG COMMENT #write (SVG_File, "\n") // Line break //###################################################################################### // BEGIN OBJECT DEFINITIONS //###################################################################################### #declare Gear = union { //torus {Hub, T1 translate <0, T1, 0> texture {pigment {color Black} finish {phong 0.0}} } // Recessed Hub Circle torus {Hole, T1 translate <0, T1, 0> texture {pigment {color Black} finish {phong 0.0}} } // Shaft hole // CIRCLE #write(SVG_File, "") // SVG COMMENT #write(SVG_File, "\n") // Line break #local Object = "circle"; #local X = OutsideCircle*2; #local Y = OutsideCircle*2; #local Radius = Hole; #local Stroke_width = 1; #local Stroke = "blue"; // write circle to file #write (SVG_File,"<", Object, " cx=\"", X, "\" cy=\"", Y, "\" r=\"", Radius, "\" style=\"stroke-width=:", Stroke_width, "; stroke:", Stroke, "; fill:none\" />") #write (SVG_File, "\n") // Line break #declare Q = 0.075; #for (Tooth1, 0, Teeth) #declare Tooth2 = Tooth1 + (0.5+Q); #declare X=0; #declare Z1=0; #declare Theta = 0; #declare Increment = 0.001; #declare Distance1 = sqrt (pow (X,2) + pow (Z1,2)); //#for (Theta, 0, Radians, 0.01) #while (Distance1 < OutsideCircle) #declare X = RootCircle * (cos(Theta) + Theta*sin(Theta)); #declare Z1 = RootCircle * (sin(Theta) - Theta*cos(Theta)); #declare Z2 = -RootCircle * (sin(Theta) - Theta*cos(Theta)); // Opposite side of involute tooth sphere {, T1 texture {pigment {color Blue} finish {phong 0.0} } rotate -y*Tooth1*AngularSpacing} sphere {, T1 texture {pigment {color Blue} finish {phong 0.0} } rotate -y*Tooth2*AngularSpacing} #declare Distance1 = sqrt (pow (X,2) + pow (Z1,2)); // radius at this point in the plotting of the gear tooth #if (Layout = true) // check if at RootCircle Circle #if ( Theta = sqrt (abs ((Distance1 / RootCircle) - 1) ) ) sphere {, MarkerCircle pigment {Green} rotate -y*Tooth1*AngularSpacing} sphere {, MarkerCircle pigment {Green} rotate -y*Tooth2*AngularSpacing} #end // check if at OutsideCircle Circle //#if ( Theta > sqrt ((pow (OutsideCircle, 2) - pow (RootCircle, 2)) / RootCircle) ) // Seems broken. Thanks, M.I.T :| #if ( Distance1 > OutsideCircle ) sphere {, MarkerCircle pigment {Yellow} rotate -y*Tooth1*AngularSpacing} sphere {, MarkerCircle pigment {Yellow} rotate -y*Tooth2*AngularSpacing} #end // Draw line of action #end // end if Layout #declare Theta = Theta + Increment; #end // end for (or while) loop // Plot Root Circle between teeth object {Segment_of_Torus ( ClearanceCircle, // radius major, T1, // radius minor, -(AngularSpacing/2)+(0.5+Q) // segment angle (in degrees) ) //----------------------------------- texture {pigment {color Blue} finish {phong 0.0} } rotate<0, -Tooth2*AngularSpacing, 0> translate y*T1 } cylinder {, T1 rotate <0, -Tooth1*AngularSpacing, 0> texture {pigment {color Blue} finish {phong 0.0} } } sphere { MarkerCircle rotate <0, -Tooth1*AngularSpacing, 0> texture {pigment {color Blue} finish {phong 0.0}} } cylinder {, T1 rotate<0, -Tooth2*AngularSpacing, 0> texture {pigment {color Blue} finish {phong 0.0} } } sphere { MarkerCircle rotate <0, -Tooth2*AngularSpacing, 0> texture {pigment {color Blue} finish {phong 0.0}} } #macro ToothPoint (Endpoint, Amount) #declare Rotation = transform {rotate <0, -Amount*AngularSpacing, 0>}; vtransform (Endpoint, Rotation) #end // end macro #declare ToothStart = ToothPoint (, Tooth1); #declare ToothEnd = ToothPoint (, Tooth2); cylinder {ToothStart, ToothEnd T1 texture {pigment {color Blue} finish {phong 0.0} } } #end // end for Tooth loop } // end union //###################################################################################### // END OBJECT DEFINITIONS //###################################################################################### // write end of SVG file #write(SVG_File,"") #write (SVG_File, "\n") // Line break #fclose SVG_File object {Gear no_shadow} //object {Gear rotate -y*((180*(0.6+Q))-180) translate x*PitchCircle*2}