/* Loial Raven's Gear code... this is about a year of work(or a week... something like that)... well, this is the most reacent... it should be quite quick... and powerful... there are a few different gear's... gear(point, rot_angle, n, pd, mdl, pa, th) <-- basic, require all info gear_n_pd (point, rot_angle, n, pd, th) -- gear_pd_mdl (point, rot_angle, pd, mdl, th) |-- only some required info... displays the last info when render gear_n_mdl (point, rot_angle, n, mdl, th) -- each of these has a different set of variables... all of them work uh... hmm... anything else i should say... oh ya, pd is accually Pressure Radius, not Pressure Diametre! this is an importaint note */ #ifndef (GEAR_INC) #declare GEAR_ING = 1; #declare _Pi = 3.141592654; // this is just a test type thingy... i hope it works... // there are a few drawbacks to this... one is that the points are assumed to be planar to the y axis #macro find_mesh_angle (gear1_pd, gear1_point, gear1_angle_y, gear2_pd, gear2_point) #local delta_point = (gear2_point-gear1_point); #local difference_angle = atan2(delta_point.z, delta_point.x)*(180/_Pi); #local difference_angles_gear1 = difference_angle-gear1_angle_y; #local offset_angle_gear2 = gear1_pd*difference_angles_gear1/gear2_pd; #local end_angle = (180+difference_angle) + offset_angle_gear2; //180 //+ offset_angle_gear2; // - difference_angles_gear1 end_angle #end #macro involute_point (r_theta) #end #macro make_3d_point (r_theta) #end #macro rotate_point (r_theta, _angle) #end #macro find_involute_angle (bc, _r) #if (_r/bc >= 1) acos(bc/_r) #else 0 #end #end #macro find_angle(bc, _r) #if (_r/bc >= 1) involute_point().v #else 0 #end #end #macro make_2d_point (r_theta) #end #macro makepoints()//(fake_bc, fake_od, fake_rd, fake_pd) #local involute_begin = (find_involute_angle(bc, rd)); #local involute1_offset = (-find_angle(bc, pd)-(cp/4)); #local involute_length = (find_involute_angle(bc, od)); #local circle_offset_val = (find_angle(bc,od)); #local involute_step = ((involute_length-involute_begin)/(quality_involute)); #local involute2_offset = -(involute1_offset); #declare angle_to_turn = (involute2_offset-(find_angle(bc, pd)))*180/_Pi; // -------------------- left involute #local i = 0; #while (i < quality_involute) #local i = i + 1; #local theta = i*involute_step+involute_begin; make_2d_point((rotate_point(involute_point(), involute1_offset))), #end // -------------------- outer points #local theta = involute1_offset+circle_offset_val; make_2d_point() make_2d_point(), #local theta = -(involute1_offset+circle_offset_val); make_2d_point() // -------------------- right involute #local i = quality_involute; #while (i >= 0) #local theta = i*involute_step+involute_begin; make_2d_point((rotate_point(involute_point(),involute1_offset)))*<-1,1>, #local i = i - 1; #end // -------------------- inside points make_2d_point(), make_2d_point() #end #macro gear(point, rot_angle, n, pd, mdl, pa, th) #ifndef (gear_texture) #declare gear_texture = texture { pigment { color rgb <1, 1, 1> } } #end #ifndef (quality_involute) #local quality_involute = 10; #end #local bc = pd * cos(pa*_Pi/180); #local od = pd + mdl; #local rd = pd - 1.157*mdl; #local cp = (2*_Pi)/n; #local tooth = prism { linear_spline linear_sweep 0, th, (quality_involute*2+2 +4), makepoints()//(fake_bc, fake_od, rd, fake_pd) texture { gear_texture } } #ifdef (gear_solid) #if (gear_solid != 0) merge { #else union { #end #else union { #end #ifndef (center) cylinder { <0,-0.00001,0>, <0,0.00001+th,0>, rd texture { gear_texture } } #else #if (center != 0) cylinder { <0,-0.00001,0>, <0,0.00001+th,0>, rd texture { gear_texture } } #end #end intersection { union { #local i = 0; #while (i < n) #local i = i + 1; object { tooth texture { gear_texture } bounded_by { cylinder { <0,-0.1,pd>, <0,0.1+th,pd>, 1.5*mdl } } rotate y*(i*(360/n)) } #end } cylinder { <0,-0.00001,0>, <0,0.00001+th,0>, od texture { gear_texture } } } rotate rot_angle + y*angle_to_turn translate point } #end #macro gear_n_pd (point, rot_angle, n, pd, th) #local mdl = (pd*2)/n; #render concat("\r\n mdl of gear is auto-set to: ", str(mdl, 5,5), "\r\n") #ifndef (pa) #declare pa = 20; #end gear(point, rot_angle, n, pd, mdl, pa, th) #end #macro gear_pd_mdl (point, rot_angle, pd, mdl, th) #local n = ceil(((pd*2)/mdl)-0.5); #local pd = (mdl*n)/2; #render concat("\r\n n of gear is auto-set to: ", str(n, 5,0), "\r\n") #render concat("pd of gear is auto-set to: ", str(pd, 5,5), "\r\n") #ifndef (pa) #declare pa = 20; #end gear(point, rot_angle, n, pd, mdl, pa, th) #end #macro gear_n_mdl (point, rot_angle, n, mdl, th) #local pd = (mdl*n)/2; #render concat("\r\n pd of gear is auto-set to: ", str(pd, 5,5), "\r\n") #ifndef (pa) #declare pa = 20; #end gear(point, rot_angle, n, pd, mdl, pa, th) #end #end