| 1 |
|
| 2 |
% référence principale : https://www.zpag.net/Machines_Simples/engrenage_droit_dent_droit.htm |
| 3 |
|
| 4 |
% p: pas primitif |
| 5 |
% pb : pas de base |
| 6 |
% Z: nbr de dents |
| 7 |
% m: module (p/pi) |
| 8 |
% rb: rayon de base |
| 9 |
% r: rayon primitif |
| 10 |
% rp: rayon de pied |
| 11 |
% rt: rayon de tête |
| 12 |
% hauteur: m + 1.25*m |
| 13 |
|
| 14 |
|
| 15 |
% global variables |
| 16 |
numeric _gear_pi,_gear_cpt,_gear_unit,_spir_point_size; |
| 17 |
numeric _g_rb[], _g_rp[], |
| 18 |
_g_rt[],_g_r[],_g_m[],_g_Z[],_g_pb[],_g_p[],_g_hauteur[],_g_alpha[],_g_rotation[],_g_spir_nbr[]; |
| 19 |
numeric _g_trans[]; |
| 20 |
string _g_type[]; |
| 21 |
pair _g_center[],_g_spir[][]; |
| 22 |
|
| 23 |
vardef _curve_length(expr c)= |
| 24 |
save N,longueur,A,B; |
| 25 |
N:=500; |
| 26 |
pair A,B; |
| 27 |
longueur:=0; |
| 28 |
for i:=0 upto N-1: |
| 29 |
A:= point (i/N) of c; |
| 30 |
B:= point((i+1)/N) of c; |
| 31 |
longueur:= longueur+length(B-A); |
| 32 |
endfor; |
| 33 |
longueur |
| 34 |
enddef; |
| 35 |
|
| 36 |
|
| 37 |
_gear_pi := 3.1415926535897932; |
| 38 |
_gear_unit := 0.5cm; |
| 39 |
_gear_cpt := 0; |
| 40 |
|
| 41 |
|
| 42 |
def getUnit= |
| 43 |
_gear_unit |
| 44 |
enddef; |
| 45 |
|
| 46 |
vardef setUnit(expr u)= |
| 47 |
_gear_unit := u; |
| 48 |
enddef; |
| 49 |
|
| 50 |
color _g_axis, _g_clavette,_g_line; |
| 51 |
_g_axis := (0.6,0.6,0.6); |
| 52 |
_g_clavette := (0.4,0.4,0.4); |
| 53 |
_g_line := black; |
| 54 |
|
| 55 |
vardef setAxisColor(expr c)= |
| 56 |
_g_axis := c; |
| 57 |
enddef; |
| 58 |
|
| 59 |
vardef setLineColor(expr c)= |
| 60 |
_g_line := c; |
| 61 |
enddef; |
| 62 |
|
| 63 |
vardef setKeyColor(expr c)= |
| 64 |
_g_clavette := c; |
| 65 |
enddef; |
| 66 |
|
| 67 |
% fonction pour calculer la rayon |
| 68 |
vardef _compute_radius(expr Z,m)= |
| 69 |
(Z*m/2) |
| 70 |
enddef; |
| 71 |
|
| 72 |
% calculer le rayon de base en fonction du rayon primitif |
| 73 |
vardef _compute_rb(expr a,alpha)= |
| 74 |
(a*cosd(alpha)) |
| 75 |
enddef; |
| 76 |
|
| 77 |
|
| 78 |
% construction des éléments d'un engrenage |
| 79 |
vardef _build_gear(expr Za,m,alpha,c,ang,ty)= |
| 80 |
% le compteur des engrenages |
| 81 |
_gear_cpt := _gear_cpt+1; |
| 82 |
% le rayon primitif |
| 83 |
_g_r[_gear_cpt] := _compute_radius(Za,m); |
| 84 |
% l'angle de pression |
| 85 |
_g_alpha[_gear_cpt] := alpha; |
| 86 |
% nombre de dents |
| 87 |
_g_Z[_gear_cpt] := Za; |
| 88 |
% module |
| 89 |
_g_m[_gear_cpt] := m; |
| 90 |
% pas primitif |
| 91 |
_g_p[_gear_cpt] := m*_gear_pi; |
| 92 |
% centre de l'engrenage |
| 93 |
_g_center[_gear_cpt] := c; |
| 94 |
% hauteur de dents |
| 95 |
_g_hauteur[_gear_cpt] := 2.25m; |
| 96 |
% rayon de base |
| 97 |
_g_rb[_gear_cpt] := _g_r[_gear_cpt]*cosd(alpha); |
| 98 |
% rayon de pied |
| 99 |
_g_rp[_gear_cpt] := _g_r[_gear_cpt]-1.25*m; |
| 100 |
% pas de pied |
| 101 |
_pp[_gear_cpt] := _g_p[_gear_cpt]*cosd(alpha); |
| 102 |
% rotation de l'engrenage |
| 103 |
_g_rotation[_gear_cpt] := ang; |
| 104 |
% type interieur ou exterieur |
| 105 |
_g_type[_gear_cpt] := ty; |
| 106 |
% on construit les points du spirograph |
| 107 |
if(ty="ex"): |
| 108 |
_build_spirograph_points(_gear_cpt); |
| 109 |
fi |
| 110 |
_gear_cpt |
| 111 |
enddef; |
| 112 |
|
| 113 |
% construction des éléments d'un engrenage |
| 114 |
vardef _build_rack(expr Za,m,alpha,c,ang,trans)= |
| 115 |
% le compteur des rack |
| 116 |
_gear_cpt := _gear_cpt+1; |
| 117 |
% l'angle de pression |
| 118 |
_g_alpha[_gear_cpt] := alpha; |
| 119 |
% nombre de dents |
| 120 |
_g_Z[_gear_cpt] := Za; |
| 121 |
% module |
| 122 |
_g_m[_gear_cpt] := m; |
| 123 |
% pas primitif |
| 124 |
_g_p[_gear_cpt] := m*_gear_pi; |
| 125 |
% centre de l'engrenage |
| 126 |
_g_center[_gear_cpt] := c; |
| 127 |
% hauteur de dents |
| 128 |
_g_hauteur[_gear_cpt] := 2.25m; |
| 129 |
% rotation de l'engrenage |
| 130 |
_g_rotation[_gear_cpt] := ang; |
| 131 |
% type interieur ou exterieur |
| 132 |
_g_trans[_gear_cpt] := trans; |
| 133 |
_g_type[_gear_cpt] := "rack"; |
| 134 |
_gear_cpt |
| 135 |
enddef; |
| 136 |
|
| 137 |
% fonction pour déterminer les points du engrenage de type |
| 138 |
% spirograph. Attention sans rotation ni translation |
| 139 |
vardef _build_spirograph_points(expr G)= |
| 140 |
save theta, spi, N, pas, l, len, spi_i,prev, curr; |
| 141 |
pair prev,curr; |
| 142 |
path spi; |
| 143 |
% spirale d'archimède rho=a*theta |
| 144 |
% on veut 1 tour jusqu'au rayon 1: |
| 145 |
% a=1/2pi |
| 146 |
for i:=0 step 10 until (_g_rp[G]*360): % angle en degre |
| 147 |
% theta en radian |
| 148 |
theta := i/180*_gear_pi; |
| 149 |
if(i=0): |
| 150 |
spi := (0,0); |
| 151 |
else: |
| 152 |
spi := spi--(1/(2*_gear_pi)*theta*cosd(i),1/(2*_gear_pi)*theta*sind(i)); |
| 153 |
fi |
| 154 |
endfor; |
| 155 |
pas := 0.4; % pas entre les points |
| 156 |
N := 1000; |
| 157 |
l := length spi; |
| 158 |
prev := point 0 of spi; |
| 159 |
len:=0; |
| 160 |
% le centre |
| 161 |
spi_i:=0; |
| 162 |
_g_spir[G][spi_i]:=(0,0); |
| 163 |
|
| 164 |
for i:=1 upto N: |
| 165 |
curr := point ((i/N)*l) of spi; |
| 166 |
len := len+length(curr-prev); |
| 167 |
if(len>pas): % si on dépasse le pas on marque |
| 168 |
spi_i:=spi_i+1; |
| 169 |
_g_spir[G][spi_i]:=prev; |
| 170 |
% on remet à zero |
| 171 |
len:=0; |
| 172 |
fi |
| 173 |
prev:=curr; |
| 174 |
endfor; |
| 175 |
_g_spir_nbr[G] := spi_i; |
| 176 |
enddef; |
| 177 |
|
| 178 |
|
| 179 |
vardef getSpirographPointNbr(expr A)= |
| 180 |
_g_spir_nbr[A] |
| 181 |
enddef; |
| 182 |
|
| 183 |
% fonction pour avoir un point «en place» de spirograph |
| 184 |
vardef getSpirographPoint(expr G, I)= |
| 185 |
if(I<=_g_spir_nbr[G]): |
| 186 |
(_g_spir[G][I] rotated _g_rotation[G] shifted _g_center[G] scaled _gear_unit) |
| 187 |
else: |
| 188 |
errmessage("Index of spirograph point too big.") |
| 189 |
fi |
| 190 |
enddef; |
| 191 |
|
| 192 |
vardef getPrimitiveRadius(expr G)= |
| 193 |
if(_g_type[G]<>"rack"): |
| 194 |
_g_r[G]*_gear_unit |
| 195 |
else: |
| 196 |
errmessage("Rack has no radius parameter") |
| 197 |
fi |
| 198 |
enddef; |
| 199 |
|
| 200 |
vardef getPressureAngle(expr G)= |
| 201 |
_g_alpha[G] |
| 202 |
enddef; |
| 203 |
|
| 204 |
|
| 205 |
vardef getModule(expr G)= |
| 206 |
_g_m[G]*_gear_unit |
| 207 |
enddef; |
| 208 |
|
| 209 |
vardef getTeethNbr(expr G)= |
| 210 |
_g_Z[G] |
| 211 |
enddef; |
| 212 |
|
| 213 |
vardef getPrimitivePitch(expr G)= |
| 214 |
_g_p[G]*_gear_unit |
| 215 |
enddef; |
| 216 |
|
| 217 |
|
| 218 |
vardef getCenter(expr G)= |
| 219 |
(_g_center[G] scaled _gear_unit) |
| 220 |
enddef; |
| 221 |
|
| 222 |
vardef getRadialPoint(expr G,t)= |
| 223 |
if(_g_type[G]="rack"): |
| 224 |
errmessage("Rack has no radial point") |
| 225 |
else: |
| 226 |
(((t*_g_r[G],0) rotated _g_rotation[G]) shifted _g_center[G] scaled _gear_unit) |
| 227 |
fi |
| 228 |
enddef; |
| 229 |
|
| 230 |
vardef getToothHeight(expr G)= |
| 231 |
_g_hauteur[G]*_gear_unit |
| 232 |
enddef; |
| 233 |
|
| 234 |
|
| 235 |
vardef getRotation(expr G)= |
| 236 |
_g_rotation[G] |
| 237 |
enddef; |
| 238 |
|
| 239 |
|
| 240 |
vardef getTranslation(expr G)= |
| 241 |
if(_g_type[G]<>"rack"): |
| 242 |
errmessage("Gear has no translation parameter") |
| 243 |
else: |
| 244 |
_g_trans[G] |
| 245 |
fi |
| 246 |
enddef; |
| 247 |
|
| 248 |
vardef getBottomRadius(expr G)= |
| 249 |
if(_g_type[G]<>"rack"): |
| 250 |
_g_rp[G]*_gear_unit |
| 251 |
else: |
| 252 |
errmessage("Rack has no radius parameter") |
| 253 |
fi |
| 254 |
enddef; |
| 255 |
|
| 256 |
|
| 257 |
vardef getTopRadius(expr G)= |
| 258 |
if(_g_type[G]<>"rack"): |
| 259 |
(_g_rp[G]+_g_hauteur[G])*_gear_unit |
| 260 |
else: |
| 261 |
errmessage("Rack has no radius parameter") |
| 262 |
fi |
| 263 |
enddef; |
| 264 |
|
| 265 |
vardef _rotation(expr p,ang)= |
| 266 |
(p rotated ang) |
| 267 |
enddef; |
| 268 |
|
| 269 |
% fonction pour définir la dent élémentaire d'un engrenage extérieur |
| 270 |
vardef _build_ex_tooth(expr G)= |
| 271 |
save p,out,t,ir,q,c,d,A,B,arc,C,D,a; |
| 272 |
path p[],out,q[]; |
| 273 |
% angle degre correspondant à l’arc p/2 |
| 274 |
t := (180/_gear_pi)*(_g_p[G]/2)/(_g_r[G])/2; |
| 275 |
% angle en degre correspondant à une dent complete |
| 276 |
t2 := 180/_g_Z[G]; |
| 277 |
|
| 278 |
% point de départ des deux développante |
| 279 |
p1 := _g_rb[G]*(1,0); |
| 280 |
p2 := _g_rb[G]*(1,0); |
| 281 |
|
| 282 |
% construction des développantes à partir de (rb,0) |
| 283 |
for i=0 upto 60: |
| 284 |
ir := i/180*_gear_pi; |
| 285 |
p1 := p1 ..(_g_rb[G]*(cosd(i)+ir*sind(i)),_g_rb[G]*(sind(i)-ir*cosd(i))); |
| 286 |
p2 := p2 .. (_g_rb[G]*(cosd(i)+ir*sind(i)),-_g_rb[G]*(sind(i)-ir*cosd(i))); |
| 287 |
endfor |
| 288 |
|
| 289 |
% on calcule l'intersection des développantes avec le cercle primitif |
| 290 |
path d; |
| 291 |
d := fullcircle scaled (2*(_g_r[G])); |
| 292 |
pair C,D; |
| 293 |
C := p1 intersectionpoint d; |
| 294 |
% on obtient l'angle |
| 295 |
a := abs(angle(C)); |
| 296 |
% on fait la rotation des deux développantes pour avoir l'angle |
| 297 |
% correspondant à la longeur p sur le cercle primitif |
| 298 |
p1 := p1 rotated -(a+t); |
| 299 |
p2 := p2 rotated (a+t); |
| 300 |
% si le cercle de base est plus petit que le cercle de pied on tronque |
| 301 |
% les développantes |
| 302 |
if(_g_rb[G]<= _g_rp[G]): |
| 303 |
d := fullcircle scaled (2*(_g_rp[G])); |
| 304 |
C := p1 intersectiontimes d; |
| 305 |
D := p2 intersectiontimes d; |
| 306 |
p1 := subpath (xpart C,length p1) of p1; |
| 307 |
p2 := subpath (xpart D,length p2) of p2; |
| 308 |
fi |
| 309 |
% on construit les partie du profil sur le cercle de pied |
| 310 |
q1 := _g_rp[G]*(cosd(-t2),sind(-t2))--_g_rp[G]*(cosd(-0.8*t2),sind(-0.8*t2)){sind(t2),cosd(t2)}..{(cosd(-t),sind(-t))} p1; |
| 311 |
q2 := _g_rp[G]*(cosd(t2),sind(t2))--_g_rp[G]*(cosd(0.8*t2),sind(0.8*t2)){sind(t2),-cosd(t2)}..{(cosd(t),sind(t))} |
| 312 |
p2 ; |
| 313 |
% on assemble les partie sur le cercle de pied, les développantes, et |
| 314 |
% les parties du cercle de tête |
| 315 |
path c; |
| 316 |
c := fullcircle scaled (2*(_g_rp[G]+_g_hauteur[G])); |
| 317 |
pair A,B; |
| 318 |
A := q1 intersectiontimes c; |
| 319 |
B := q2 intersectiontimes c; |
| 320 |
path arc; |
| 321 |
arc := subpath (8-ypart A, ypart B) of c; |
| 322 |
((subpath (0, xpart A) of q1) --arc-- reverse((subpath (0, xpart B) of q2))) |
| 323 |
enddef; |
| 324 |
|
| 325 |
|
| 326 |
% fonction pour définir la dent élémentaire d'un engrenage intérieur |
| 327 |
vardef _build_in_tooth(expr G)= |
| 328 |
save p,out,t,ir,q,c,d,A,B,arc,C,D,a,ra; |
| 329 |
path p[],out,q[]; |
| 330 |
% angle degre correspondant à l’arc p/2 |
| 331 |
t := (180/_gear_pi)*(_g_p[G]/2)/(_g_r[G])/2; |
| 332 |
% angle en degre correspondant à une dent complete |
| 333 |
t2 := 180/_g_Z[G]; |
| 334 |
|
| 335 |
% point de départ des deux développante |
| 336 |
p1 := _g_rb[G]*(1,0); |
| 337 |
p2 := _g_rb[G]*(1,0); |
| 338 |
|
| 339 |
% construction des développantes à partir de (rb,0) |
| 340 |
for i=0 upto 60: |
| 341 |
ir := i/180*_gear_pi; |
| 342 |
p1 := p1 ..(_g_rb[G]*(cosd(i)+ir*sind(i)),_g_rb[G]*(sind(i)-ir*cosd(i))); |
| 343 |
p2 := p2 .. (_g_rb[G]*(cosd(i)+ir*sind(i)),-_g_rb[G]*(sind(i)-ir*cosd(i))); |
| 344 |
endfor |
| 345 |
|
| 346 |
% on calcule l'intersection des développantes avec le cercle primitif |
| 347 |
path d; |
| 348 |
d := fullcircle scaled (2*(_g_r[G])); |
| 349 |
pair C,D; |
| 350 |
C := p1 intersectionpoint d; |
| 351 |
% on obtient l'angle |
| 352 |
a := abs(angle(C)); |
| 353 |
% on fait la rotation des deux développantes pour avoir l'angle |
| 354 |
% correspondant à la longeur p sur le cercle primitif |
| 355 |
p1 := p1 rotated -(a+t); |
| 356 |
p2 := p2 rotated (a+t); |
| 357 |
% si le cercle de base est plus petit que le cercle de pied on tronque |
| 358 |
% les développantes |
| 359 |
%%% difference %%%%%% |
| 360 |
%% rayon pour tronquer |
| 361 |
ra := _g_r[G]-1*_g_m[G]; |
| 362 |
|
| 363 |
d := fullcircle scaled (2*(ra)); |
| 364 |
C := p1 intersectiontimes d; |
| 365 |
D := p2 intersectiontimes d; |
| 366 |
p1 := subpath (xpart C,length p1) of p1; |
| 367 |
p2 := subpath (xpart D,length p2) of p2; |
| 368 |
%%%%%% le reste identique à l'extérieur %%%%%%%%%% |
| 369 |
% on construit les partie du profil sur le cercle de pied |
| 370 |
q1 := (_g_rp[G]+0.15*_g_m[G])*(cosd(-t2),sind(-t2))--(_g_rp[G]+0.15*_g_m[G])*(cosd(-0.8*t2),sind(-0.8*t2)){sind(t2),cosd(t2)}..{(cosd(-t),sind(-t))} p1; |
| 371 |
q2 := (_g_rp[G]+0.15*_g_m[G])*(cosd(t2),sind(t2))--(_g_rp[G]+0.15*_g_m[G])*(cosd(0.8*t2),sind(0.8*t2)){sind(t2),-cosd(t2)}..{(cosd(t),sind(t))} |
| 372 |
p2 ; |
| 373 |
% on assemble les partie sur le cercle de pied, les développantes, et |
| 374 |
% les parties du cercle de tête |
| 375 |
path c; |
| 376 |
c := fullcircle scaled (2*(_g_rp[G]+_g_hauteur[G]+0.15*_g_m[G])); |
| 377 |
pair A,B; |
| 378 |
A := q1 intersectiontimes c; |
| 379 |
B := q2 intersectiontimes c; |
| 380 |
path arc; |
| 381 |
arc := subpath (8-ypart A, ypart B) of c; |
| 382 |
((subpath (0, xpart A) of q1) --arc-- reverse((subpath (0, xpart B) of q2))) |
| 383 |
enddef; |
| 384 |
|
| 385 |
% fonction pour construire le bord denté par rotation de la dent élémentaire |
| 386 |
vardef _build_ex_gear_path(expr G)= |
| 387 |
save p,ee; |
| 388 |
path p,ee; |
| 389 |
ee := _build_ex_tooth(G); |
| 390 |
p := ee; |
| 391 |
for i=1 upto _g_Z[G]-1: |
| 392 |
p := p-- (ee rotated (i/_g_Z[G]*360)) ; |
| 393 |
endfor |
| 394 |
((p -- cycle) ) |
| 395 |
%p |
| 396 |
enddef; |
| 397 |
|
| 398 |
vardef _build_in_gear_path(expr G)= |
| 399 |
save p,ee; |
| 400 |
path p,ee; |
| 401 |
ee := _build_in_tooth(G); |
| 402 |
p := ee; |
| 403 |
for i=1 upto _g_Z[G]-1: |
| 404 |
p := p-- (ee rotated (i/_g_Z[G]*360)) ; |
| 405 |
endfor |
| 406 |
((p -- cycle) ) |
| 407 |
%p |
| 408 |
enddef; |
| 409 |
|
| 410 |
vardef _build_rack_tooth(expr G)= |
| 411 |
( (_g_p[G]/2,-1.25*_g_m[G]) |
| 412 |
--(_g_p[G]/4+sind(_g_alpha[G])/cosd(_g_alpha[G])*1.25*_g_m[G],-1.25*_g_m[G]) |
| 413 |
-- (_g_p[G]/4-sind(_g_alpha[G])/cosd(_g_alpha[G])*1.0*_g_m[G],_g_m[G]) |
| 414 |
-- (-(_g_p[G]/4-sind(_g_alpha[G])/cosd(_g_alpha[G])*1.0*_g_m[G]),_g_m[G]) |
| 415 |
-- |
| 416 |
(-(_g_p[G]/4+sind(_g_alpha[G])/cosd(_g_alpha[G])*1.25*_g_m[G]),-1.25*_g_m[G]) |
| 417 |
--(-_g_p[G]/2,-1.25*_g_m[G])) rotated 90 |
| 418 |
enddef; |
| 419 |
% crémaillère |
| 420 |
vardef _build_rack_path(expr G)= |
| 421 |
save ad, p,ee; |
| 422 |
path p,ee; |
| 423 |
ee := _build_rack_tooth(G); |
| 424 |
ad:=0; |
| 425 |
% si le nombre de dents est pair, |
| 426 |
if((_g_Z[G] mod 2 )= 0): |
| 427 |
ad := 1; |
| 428 |
fi |
| 429 |
for i:=((_g_Z[G]+ad-1)/2) downto (-(_g_Z[G]+ad-1)/2): |
| 430 |
if(i=((_g_Z[G]+ad-1)/2)): |
| 431 |
p:=(ee shifted (0,i*_g_p[G])); |
| 432 |
else: |
| 433 |
p := p--(ee shifted (0,i*_g_p[G])); |
| 434 |
fi |
| 435 |
endfor |
| 436 |
p |
| 437 |
enddef; |
| 438 |
|
| 439 |
% simple wrapper |
| 440 |
vardef buildExternalGear(expr Za, m, alpha,c,ang)= |
| 441 |
% on construit l'engrenage engrenage |
| 442 |
_build_gear(Za,m,alpha,c,ang,"ex") |
| 443 |
enddef; |
| 444 |
|
| 445 |
|
| 446 |
% simple wrapper |
| 447 |
vardef buildInternalGear(expr Za, m, alpha,c,ang)= |
| 448 |
% on construit l'engrenage engrenage |
| 449 |
_build_gear(Za,m,alpha,c,ang,"in") |
| 450 |
enddef; |
| 451 |
|
| 452 |
% simple wrapper |
| 453 |
vardef buildRack(expr Za, m, alpha,c,ang,trans)= |
| 454 |
% on construit l'engrenage engrenage |
| 455 |
_build_rack(Za,m,alpha,c,ang,trans) |
| 456 |
enddef; |
| 457 |
|
| 458 |
% fonction qui construit deux engrenages extérieurs liés |
| 459 |
% Zb: nombre de dents du premier engrenage |
| 460 |
% Za: nombre de dents du deuxième engrenage |
| 461 |
% m: module |
| 462 |
% alpha: angle de portée |
| 463 |
% ang: angle en degré de rotation du premier engrenage |
| 464 |
% rota: angle de rotation du centre du deuxième engrenage |
| 465 |
vardef buildExternalGearPair(expr Za,Zb, m, alpha,c,ang,rota)= |
| 466 |
save ct,G,rotation; |
| 467 |
pair out,ct; |
| 468 |
% on construit le premier engrenage |
| 469 |
G1 := _build_gear(Za,m,alpha,c,ang,"ex"); |
| 470 |
% on calcule les coordonnées du centre du deuxième engrenange |
| 471 |
ct := c+((_compute_radius(Za,m)+_compute_radius(Zb,m),0) rotated rota); |
| 472 |
% on calcule la rotation du second engrenage |
| 473 |
rotation := -Za/Zb*(ang)+(Za+Zb)/Zb*rota +180/Zb |
| 474 |
; |
| 475 |
% on construit le deuxième engrenage |
| 476 |
G2 := _build_gear(Zb,m,alpha,ct,rotation,"ex"); |
| 477 |
(G1,G2) |
| 478 |
enddef; |
| 479 |
|
| 480 |
% fonction qui construit un engrenage lié à engrenage déjà existant |
| 481 |
% G: (numeric) identificateur du premier engrenage |
| 482 |
% Zb: nombre de dents de l'engrenage à construire |
| 483 |
% rota: angle de rotation du centre du deuxième engrenage |
| 484 |
vardef buildExternalGearFor(expr G,Zb,rota)= |
| 485 |
save ct,rotation,Z; |
| 486 |
pair ct; |
| 487 |
if(_g_type[G]="ex"): |
| 488 |
ct := _g_center[G]+((_compute_radius(_g_Z[G],_g_m[G])+_compute_radius(Zb,_g_m[G]),0) rotated rota); |
| 489 |
rotation := -_g_Z[G]/Zb*(_g_rotation[G])+(_g_Z[G]+Zb)/Zb*rota +180/Zb ; |
| 490 |
Z := _build_gear(Zb,_g_m[G],_g_alpha[G],ct,rotation,"ex"); |
| 491 |
elseif(_g_type[G]="in"): |
| 492 |
ct := _g_center[G]+((_g_m[G]*(_g_Z[G]-Zb)/2,0) rotated rota); |
| 493 |
rotation := _g_Z[G]/Zb*(_g_rotation[G])+(_g_Z[G]+Zb)/Zb*rota ; |
| 494 |
Z := _build_gear(Zb,_g_m[G],_g_alpha[G],ct,rotation,"ex"); |
| 495 |
fi |
| 496 |
Z |
| 497 |
enddef; |
| 498 |
|
| 499 |
|
| 500 |
% fonction qui construit un engrenage interne lié à engrenage externe déjà |
| 501 |
% existant |
| 502 |
% G: (numeric) identificateur du premier engrenage |
| 503 |
% Zb: nombre de dents de l'engrenage à construire |
| 504 |
% rota: angle de rotation du centre du deuxième engrenage |
| 505 |
vardef buildInternalGearFor(expr G,Zb,rota)= |
| 506 |
save ct,Z,rotation; |
| 507 |
pair ct; |
| 508 |
if(Zb<_g_Z[G]): |
| 509 |
errmessage("Number of tooth of the internal gear must be greater"); |
| 510 |
elseif(_g_type[G]="in"): |
| 511 |
errmessage("The meshed gear must be external."); |
| 512 |
else: |
| 513 |
ct := _g_center[G]-((_compute_radius(Zb,_g_m[G])-_g_r[G],0) rotated rota); |
| 514 |
rotation := +_g_Z[G]/Zb*(_g_rotation[G])-(_g_Z[G]-Zb)/Zb*rota ; |
| 515 |
Z := _build_gear(Zb,_g_m[G],_g_alpha[G],ct,rotation,"in"); |
| 516 |
fi |
| 517 |
Z |
| 518 |
enddef; |
| 519 |
|
| 520 |
|
| 521 |
% fonction qui construit deux engrenages liés |
| 522 |
% un est à l'intérieur de l'autre |
| 523 |
% Zb: nombre de dents du premier engrenage |
| 524 |
% Za: nombre de dents du deuxième engrenage |
| 525 |
% m: module |
| 526 |
% alpha: angle de portée |
| 527 |
% ang: angle en degré de rotation du premier engrenage |
| 528 |
% rota: angle de rotation du centre du deuxième engrenage |
| 529 |
vardef buildInternalGearPair(expr Za,Zb, m, alpha,c,ang,rota)= |
| 530 |
save ct,G,rotation; |
| 531 |
pair ct; |
| 532 |
% on construit le premier engrenage |
| 533 |
% à l'intérieur duquel va être l'autre |
| 534 |
G1 := _build_gear(Za,m,alpha,c,ang,"in"); |
| 535 |
% on calcule les coordonnées du centre du deuxième engrenange |
| 536 |
ct := c+((m*(Za-Zb)/2,0) rotated rota); |
| 537 |
% on calcule la rotation du second engrenage |
| 538 |
rotation := Za/Zb*(ang)-(Za-Zb)/Zb*rota; |
| 539 |
% on construit le deuxième engrenage |
| 540 |
G2 := _build_gear(Zb,m,alpha,ct,rotation,"ex"); |
| 541 |
(G1,G2) |
| 542 |
enddef; |
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
% création d'un engrenage sur le même axe et la même rotation. |
| 547 |
% Solidaire à un précédent |
| 548 |
vardef buildCompoundGear(expr G, Zb, m,alpha)= |
| 549 |
_build_gear(Zb,m,alpha,_g_center[G],_g_rotation[G],"ex") |
| 550 |
enddef; |
| 551 |
|
| 552 |
|
| 553 |
% fonction qui construit un engrenage et crémaillère liés |
| 554 |
% Zb: nombre de dents du premier engrenage |
| 555 |
% Za: nombre de dents de la crémaillère |
| 556 |
% m: module |
| 557 |
% alpha: angle de portée |
| 558 |
% ang: angle en degré de rotation de l'engrenage |
| 559 |
% rota: angle de rotation du centre de la crémaillère |
| 560 |
vardef buildGearRackPair(expr Za,Zb, m, alpha,c,ang,rota)= |
| 561 |
save ct,G,rotation,trans,R,t,d,p; |
| 562 |
pair ct; |
| 563 |
R := _compute_radius(Za,m); |
| 564 |
% on construit le premier engrenage |
| 565 |
G1 := _build_gear(Za,m,alpha,c,ang,"ex"); |
| 566 |
% on calcule les coordonnées du centre du deuxième engrenange |
| 567 |
ct := c+((R,0) rotated rota); |
| 568 |
% on calcule la rotation du second engrenage |
| 569 |
rotation := rota; |
| 570 |
% distance parcouru avec rota sur le cercle primitif |
| 571 |
d := (_gear_pi*rota/180)*R; |
| 572 |
p := _gear_pi*m; |
| 573 |
% nombre de dents pour recentrer la crémaillère par rapport à la rotation de |
| 574 |
% centre |
| 575 |
t:=floor(d/p); |
| 576 |
trans := _gear_pi*(ang)/180*R-(d-t*p)+_gear_pi*m/2; |
| 577 |
% on construit le deuxième engrenage |
| 578 |
G2 := _build_rack(Zb,m,alpha,ct,rotation,trans); |
| 579 |
(G1,G2) |
| 580 |
enddef; |
| 581 |
|
| 582 |
|
| 583 |
% fonction qui construit une crémaillère liée à un engrenage existant |
| 584 |
% G: identifiant de l'engrenage |
| 585 |
% Zb: nombre de dents de la crémaillère |
| 586 |
% rota: angle de rotation du centre de la crémaillère |
| 587 |
vardef buildRackFor(expr G,Zb,rota)= |
| 588 |
save ct,rotation,trans,R,t,d,p; |
| 589 |
pair ct; |
| 590 |
R := _g_r[G]; |
| 591 |
% on calcule les coordonnées du centre du deuxième engrenange |
| 592 |
ct := _g_center[G]+((R,0) rotated rota); |
| 593 |
% on calcule la rotation du second engrenage |
| 594 |
rotation := rota; |
| 595 |
% distance parcouru avec rota sur le cercle primitif |
| 596 |
d := (_gear_pi*rota/180)*R; |
| 597 |
p := _gear_pi*_g_m[G]; |
| 598 |
% nombre de dents pour recentrer la crémaillère par rapport à la rotation de |
| 599 |
% centre |
| 600 |
t:=floor(d/p); |
| 601 |
trans := _gear_pi*(_g_rotation[G])/180*R-(d-t*p)+_gear_pi*_g_m[G]/2; |
| 602 |
% on construit le deuxième engrenage |
| 603 |
_build_rack(Zb,_g_m[G],_g_alpha[G],ct,rotation,trans) |
| 604 |
enddef; |
| 605 |
|
| 606 |
|
| 607 |
_spir_point_size := 0.15; |
| 608 |
|
| 609 |
vardef setSpirographPointSize(expr s)= |
| 610 |
_spir_point_size := s; |
| 611 |
enddef; |
| 612 |
|
| 613 |
def getSpirographPointSize= |
| 614 |
_spir_point_size |
| 615 |
enddef; |
| 616 |
|
| 617 |
% fonction pour dessiner un engrenage |
| 618 |
vardef drawGear(expr G, c, typ) text p= |
| 619 |
save teeth,axe,entre,im,R,trou,l,spi,theta,N,pas,prev,curr, len,shape,cc; |
| 620 |
path teeth,axe,entre,trou,spi,shape; |
| 621 |
pair prev,curr; |
| 622 |
boolean cc; |
| 623 |
%booléen pour colorier ou non |
| 624 |
if(string c): |
| 625 |
cc:=false; |
| 626 |
else: |
| 627 |
cc:=true; |
| 628 |
fi |
| 629 |
picture im; |
| 630 |
if(_g_type[G] = "ex"): |
| 631 |
teeth := _build_ex_gear_path(G) scaled _gear_unit; |
| 632 |
if(typ="classical"): |
| 633 |
axe := fullcircle scaled (0.3*2*_g_r[G]) scaled _gear_unit; |
| 634 |
entre := (unitsquare shifted (-0.5,-0.5) xscaled (0.08*_g_r[G]) yscaled (0.1*_g_r[G])) shifted |
| 635 |
(0.3*(_g_r[G],0)) scaled _gear_unit; |
| 636 |
im := image( |
| 637 |
if cc: fill teeth withcolor c; fi |
| 638 |
draw teeth withcolor _g_line; |
| 639 |
if cc: fill axe withcolor _g_axis; fi |
| 640 |
draw axe withcolor _g_line; |
| 641 |
if cc: fill entre withcolor _g_clavette; else: unfill entre; fi |
| 642 |
draw entre withcolor _g_line; |
| 643 |
); |
| 644 |
elseif(typ="clockwork"): |
| 645 |
% si le rayon est suffisamment grand par rapport au module |
| 646 |
if(_g_r[G]>3*_g_hauteur[G]): |
| 647 |
R1 := 0.2*_g_r[G]; |
| 648 |
R2 := _g_r[G]-3*_g_m[G]; |
| 649 |
trou := |
| 650 |
((R1,0.3*R1)--(R2,0.3*R1){-0.05,1}..(0.3*R1,R2)--(0.3*R1,R1){1,-0.3}..cycle) scaled |
| 651 |
_gear_unit; |
| 652 |
im := image( |
| 653 |
l := length teeth; |
| 654 |
if cc: fill teeth -- ((R2,0) scaled _gear_unit)-- reverse trou -- (0,0) -- reverse (trou rotated |
| 655 |
90) -- (0,0) -- |
| 656 |
reverse (trou rotated 180) -- (0,0) -- reverse (trou rotated |
| 657 |
270)-- (0,0)-- ((R2,0) scaled _gear_unit) -- cycle |
| 658 |
withcolor c; fi |
| 659 |
draw teeth withcolor _g_line; |
| 660 |
draw trou withcolor _g_line; |
| 661 |
draw trou rotated 90 withcolor _g_line; |
| 662 |
draw trou rotated 180 withcolor _g_line; |
| 663 |
draw trou rotated 270 withcolor _g_line; |
| 664 |
draw fullcircle scaled ((2*0.6*R1)*_gear_unit) withcolor _g_line; |
| 665 |
draw ((-0.6*R1,0)--(0.6*R1,0)) scaled _gear_unit withcolor _g_line; |
| 666 |
); |
| 667 |
|
| 668 |
else: |
| 669 |
R1 := 0.2*_g_r[G]; |
| 670 |
im:=image( |
| 671 |
if cc: fill teeth withcolor c;fi |
| 672 |
draw teeth withcolor _g_line; |
| 673 |
draw fullcircle scaled ((2*0.6*R1)*_gear_unit) withcolor _g_line; |
| 674 |
draw ((-0.6*R1,0)--(0.6*R1,0)) scaled _gear_unit withcolor _g_line; |
| 675 |
); |
| 676 |
fi |
| 677 |
elseif(typ="spirograph"): |
| 678 |
axe := fullcircle scaled (0.3*2*_g_r[G]) scaled _gear_unit; |
| 679 |
entre := (unitsquare shifted (-0.5,-0.5) xscaled (0.08*_g_r[G]) yscaled (0.1*_g_r[G])) shifted |
| 680 |
(0.3*(_g_r[G],0)) scaled _gear_unit; |
| 681 |
im := image( |
| 682 |
if cc: fill teeth withcolor c;fi |
| 683 |
draw teeth withcolor _g_line; |
| 684 |
for i:=0 upto _g_spir_nbr[G]: |
| 685 |
if cc: fill fullcircle scaled (_spir_point_size*_gear_unit) shifted |
| 686 |
(_g_spir[G][i] scaled _gear_unit) withcolor background; fi |
| 687 |
draw fullcircle scaled (_spir_point_size*_gear_unit) shifted |
| 688 |
(_g_spir[G][i] scaled _gear_unit) withcolor _g_line; |
| 689 |
endfor; |
| 690 |
); |
| 691 |
else: |
| 692 |
errmessage("This type of drawing does not exist.") |
| 693 |
fi |
| 694 |
elseif(_g_type[G]="in"): |
| 695 |
if(typ="classical"): |
| 696 |
axe := fullcircle scaled (2*(_g_r[G]+2.5*_g_m[G])) scaled _gear_unit; |
| 697 |
teeth := _build_in_gear_path(G) scaled _gear_unit; |
| 698 |
im := image( |
| 699 |
if cc: fill axe-- reverse teeth--cycle withcolor c; fi |
| 700 |
draw teeth withcolor _g_line; |
| 701 |
draw axe withcolor _g_line; |
| 702 |
); |
| 703 |
else: |
| 704 |
errmessage("This type of drawing does not exist."); |
| 705 |
fi |
| 706 |
fi |
| 707 |
draw im rotated _g_rotation[G] shifted (_g_center[G] scaled _gear_unit) p; |
| 708 |
enddef; |
| 709 |
|
| 710 |
vardef drawRack(expr G,c) text p= |
| 711 |
save teeth, shape,im,cc; |
| 712 |
path teeth, shape; |
| 713 |
picture im; |
| 714 |
boolean cc; |
| 715 |
%booléen pour colorier ou non |
| 716 |
if(string c): |
| 717 |
cc:=false; |
| 718 |
else: |
| 719 |
cc:=true; |
| 720 |
fi |
| 721 |
|
| 722 |
|
| 723 |
teeth := _build_rack_path(G); |
| 724 |
shape := ((point 0 of teeth)+(0.6*_g_hauteur[G],0))--teeth -- ((point |
| 725 |
(length teeth) of teeth)+(0.6*_g_hauteur[G],0))--cycle; |
| 726 |
im := image( |
| 727 |
if cc: fill (shape scaled _gear_unit) withcolor c; fi |
| 728 |
draw (shape scaled _gear_unit) withcolor _g_line; |
| 729 |
); |
| 730 |
draw im shifted (0,_g_trans[G]*_gear_unit) rotated _g_rotation[G] shifted |
| 731 |
(_g_center[G] scaled _gear_unit ) p; |
| 732 |
enddef; |
| 733 |
|
| 734 |
|
| 735 |
vardef primitiveCircle(expr G)= |
| 736 |
if(_g_type[G]<>"rack"): |
| 737 |
fullcircle scaled (2*_g_r[G]) shifted _g_center[G] scaled _gear_unit |
| 738 |
else: |
| 739 |
errmessage("Rack does not have circle parameters."); |
| 740 |
fi |
| 741 |
enddef; |
| 742 |
|
| 743 |
|
| 744 |
vardef baseCircle(expr G)= |
| 745 |
|
| 746 |
if(_g_type[G]<>"rack"): |
| 747 |
fullcircle scaled (2*_g_rb[G]) scaled _gear_unit |
| 748 |
else: |
| 749 |
errmessage("Rack does not have circle parameters."); |
| 750 |
fi |
| 751 |
|
| 752 |
enddef; |
| 753 |
|
| 754 |
|
| 755 |
vardef bottomCircle(expr G)= |
| 756 |
|
| 757 |
if(_g_type[G]<>"rack"): |
| 758 |
fullcircle scaled (2*_g_rp[G]) scaled _gear_unit |
| 759 |
else: |
| 760 |
errmessage("Rack does not have circle parameters."); |
| 761 |
fi |
| 762 |
|
| 763 |
enddef; |
| 764 |
|
| 765 |
|
| 766 |
vardef topCircle(expr G)= |
| 767 |
|
| 768 |
if(_g_type[G]<>"rack"): |
| 769 |
fullcircle scaled (2*(_g_rp[G]+_g_hauteur[G])) scaled _gear_unit |
| 770 |
else: |
| 771 |
errmessage("Rack does not have circle parameters."); |
| 772 |
fi |
| 773 |
|
| 774 |
enddef; |
| 775 |
|
| 776 |
vardef primitiveLine(expr G)= |
| 777 |
|
| 778 |
if(_g_type[G]<>"rack"): |
| 779 |
errmessage("Gear does not have line parameters."); |
| 780 |
else: |
| 781 |
((0,(_g_Z[G]/2+1)*_g_p[G]*_gear_unit)--(0,-(_g_Z[G]/2+1)*_g_p[G]*_gear_unit)) shifted (0,_g_trans[G]*_gear_unit) |
| 782 |
rotated _g_rotation[G] shifted (_g_center[G] scaled _gear_unit) |
| 783 |
fi |
| 784 |
enddef; |
| 785 |
|
| 786 |
vardef baseLine(expr G)= |
| 787 |
|
| 788 |
if(_g_type[G]<>"rack"): |
| 789 |
errmessage("Gear does not have line parameters."); |
| 790 |
else: |
| 791 |
((_g_m[G]*_gear_unit,(_g_Z[G]/2+1)*_g_p[G]*_gear_unit)--(_g_m[G]*_gear_unit,-(_g_Z[G]/2+1)*_g_p[G]*_gear_unit)) shifted (0,_g_trans[G]*_gear_unit) |
| 792 |
rotated _g_rotation[G] shifted (_g_center[G] scaled _gear_unit) |
| 793 |
fi |
| 794 |
enddef; |
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
vardef bottomLine(expr G)= |
| 799 |
|
| 800 |
if(_g_type[G]<>"rack"): |
| 801 |
errmessage("Gear does not have line parameters."); |
| 802 |
else: |
| 803 |
((1.25*_g_m[G]*_gear_unit,(_g_Z[G]/2+1)*_g_p[G]*_gear_unit)--(1.25*_g_m[G]*_gear_unit,-(_g_Z[G]/2+1)*_g_p[G]*_gear_unit)) shifted (0,_g_trans[G]*_gear_unit) |
| 804 |
rotated _g_rotation[G] shifted (_g_center[G] scaled _gear_unit) |
| 805 |
fi |
| 806 |
enddef; |
| 807 |
|
| 808 |
|
| 809 |
vardef topLine(expr G)= |
| 810 |
|
| 811 |
if(_g_type[G]<>"rack"): |
| 812 |
errmessage("Gear does not have line parameters."); |
| 813 |
else: |
| 814 |
((-_g_m[G]*_gear_unit,(_g_Z[G]/2+1)*_g_p[G]*_gear_unit)--(-_g_m[G]*_gear_unit,-(_g_Z[G]/2+1)*_g_p[G]*_gear_unit)) shifted (0,_g_trans[G]*_gear_unit) |
| 815 |
rotated _g_rotation[G] shifted (_g_center[G] scaled _gear_unit) |
| 816 |
fi |
| 817 |
enddef; |
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
vardef spirographCurve(expr A,B,I,ang)= |
| 824 |
save spir,G,ct,Z,rota,S; |
| 825 |
path spir; |
| 826 |
numeric rota[]; |
| 827 |
pair ct[],S; |
| 828 |
ct1 := _g_center[A]; % centre du «repere» |
| 829 |
% le point considéré |
| 830 |
spir := _g_spir[B][I] rotated (_g_rotation[B]) shifted _g_center[B]; |
| 831 |
rota3 := 0; |
| 832 |
for i:=1 step 2 until ang: |
| 833 |
% rotation de cB par rapport à cA |
| 834 |
rota1 := i; |
| 835 |
ct2 := _g_center[B] shifted (-ct1) rotated rota1 shifted ct1; |
| 836 |
if(_g_type[A]="in"): |
| 837 |
rota2 := -(_g_Z[A]-_g_Z[B])/_g_Z[B]*rota1; % |
| 838 |
elseif(_g_type[A]="ex"): |
| 839 |
rota2 := (_g_Z[A]+_g_Z[B])/_g_Z[B]*rota1; % |
| 840 |
fi |
| 841 |
S := _g_spir[B][I] rotated (_g_rotation[B]+rota2) shifted ct2; |
| 842 |
spir := spir --S; |
| 843 |
endfor; |
| 844 |
(spir shifted ct1 scaled _gear_unit) |
| 845 |
enddef; |
| 846 |
|
| 847 |
vardef cycloidCurve(expr A,B,ang)= |
| 848 |
save cyc,G,ct,Z,rota,S; |
| 849 |
path cyc; |
| 850 |
numeric rota[]; |
| 851 |
pair ct[],S; |
| 852 |
ct1 := _g_center[A]; % centre du «repere» |
| 853 |
% le point considéré |
| 854 |
cyc := ((_g_r[B],0)) rotated (_g_rotation[B]) shifted _g_center[B]; |
| 855 |
for i:=2 step 2 until ang: |
| 856 |
% rotation de cB par rapport à cA |
| 857 |
rota1 := i; |
| 858 |
ct2 := _g_center[B] shifted (-ct1) rotated rota1 shifted ct1; |
| 859 |
if(_g_type[A]="in"): |
| 860 |
rota2 := -(_g_Z[A]-_g_Z[B])/_g_Z[B]*rota1; % |
| 861 |
elseif(_g_type[A]="ex"): |
| 862 |
rota2 := (_g_Z[A]+_g_Z[B])/_g_Z[B]*rota1; % |
| 863 |
fi |
| 864 |
S := ((_g_r[B],0) rotated (_g_rotation[B]+rota2)) shifted ct2; |
| 865 |
cyc := cyc--S; |
| 866 |
endfor; |
| 867 |
(cyc shifted ct1 scaled _gear_unit) |
| 868 |
enddef; |
| 869 |
|