Debian Codegraph @

texmf-dist/doc/latex/figput/example/example.tex

raw
1
2 \documentclass[10pt]{article}
3
4 % This file was written to demonstrate this package.
5 \usepackage{figput}
6
7 % Allows various tweaks to itemize as optional arguments.
8 \usepackage{enumitem}
9
10 % Allows \verb in footnotes
11 \usepackage{fancyvrb}
12
13
14 \begin{document}
15
16 % Need this for fancyvrb to work.
17 \VerbatimFootnotes
18
19
20 % Getting this right may involve some experimentation.
21 \SetInnerMargin{135pt}
22 \SetOuterMargin{135pt}
23
24 % Turn this on to show figures or off to save time.
25 \NeverSkip
26
27 % Some of the \FigPut commands refer to this code.
28 \LoadFigureCode{externalcode.js}
29
30
31 This document demonstrates some of the features of \textsc{FigPut}. It
32 consists of a series of snippets of exposition. There are a few simple
33 examples -- B\'ezier curves, the ellipse and diffiusion -- followed by
34 a more extended example about gears.
35
36 % Much of what follows uses the figput *environment*. This uses the
37 % \FigPut *command*.
38 \begin{figure}[b!]
39 \FigPut{bezier,175bp}[17bp,22bp,done,skip]
40 \caption{A Cubic B\'ezier Curve}
41 \label{fig-cubic-bezier}
42 \end{figure}
43
44 \section{Example: B\'ezier Curves}
45
46 B\'ezier curves are a convenient way of defining curves in the
47 plane. They can be defined using Bernstein polynomials. The
48 Bernstein polynomials of degree $n$ are defined by
49 $$B_i^n(t) = {n \choose i} t^i (1-t)^{n-i},\qquad i=0,\ldots,n.$$
50 A cubic B\'ezier curve is a linear combination of the Bernstein
51 polynomials of degree 3:
52 $$C(t) = \sum_{i=0}^3 p_i B_i^3(t),$$
53 where the four $p_i$ are points in the plane and $t$ is limited to
54 $[0,1]$. This can be written as the pair of equations $(x(t),y(t))=
55 C(t)$, where
56 \begin{eqnarray*}
57 x(t) &=& x_1\cdot (1-t)^3 + x_2\cdot 3(1-t)^2t + x_3\cdot 3(1-t)t^2 +
58 x_4\cdot t^3 \\
59 y(t) &=& y_1\cdot (1-t)^3 + y_2\cdot 3(1-t)^2t + y_3\cdot 3(1-t)t^2 +
60 y_4\cdot t^3,
61 \end{eqnarray*}
62 $(x_i,y_i) = p_i$ and the indices on the $p_i$ have been
63 shifted. We have $C(0) = p_1$ and $C(1)=p_4$ and the other two points
64 act as ``controls.'' See Figure (\ref{fig-cubic-bezier}), noting that
65 the line determined by the pair of points controlling each end of the curve is
66 tangent to the corresponding end-point of the B\'ezier curve.
67
68 \section{Example: Drawing an Ellipse}
69
70 One way to define an ellipse is illustrated by Figure
71 (\ref{fig-ellipse-draw}). Choose two points, $F_1$ and $F_2$ (the
72 {\bf foci}), and fix some $k>0$. The ellipse is then
73 the set of points, $P$, satisfying
74 $$d(P,F_1) + d(P,F_2) = k,$$
75 where $d(A,B)$ is the distance from $A$ to $B$.
76
77 The figure makes it clear why this is sometimes refered to as the
78 ``tacks and string'' definition. Imagine tacking each end of a bit of
79 string, of length $k$, to the two foci; then tracing out the ellipse
80 by holding a pencil at the limit of what the string will allow as the
81 pencil travels about the foci.
82
83 \begin{figure}
84 \begin{figput}{elldraw,175bp}[done,skip]
85 function elldraw(ctx) {
86
87 // The length of the string.
88 let k = 150;
89
90 let yaxis = 85;
91
92 // Limit these two points to be along the line y = yaxis.
93 let w1 = DraggableDotWidget.register(ctx,125,yaxis,'d1');
94 let w2 = DraggableDotWidget.register(ctx,225,yaxis,'d2');
95
96 // We need a LoopAnimWidget for an animation, even though we never want
97 // see the widget.
98 let numSteps = 1000;
99 let loopw = LoopAnimWidget.register(ctx,-100,100,1.0,
100 false, // hidden
101 numSteps, // steps per loop
102 0, // starting step
103 10, // ms time step
104 false,false,false,false,false, // nothing is visible
105 'loop');
106
107 w1.widgetY = yaxis;
108 w2.widgetY = yaxis;
109
110 // The origin is the mid-point.
111 let cx = (w1.widgetX + w2.widgetX) / 2;
112 let cy = yaxis;
113
114 // c = distance from foci to center, a = x-radius and b = y-radius.
115 let c = Math.abs(w1.widgetX - cx);
116 let a = k / 2;
117 let b = Math.sqrt(a*a - c*c);
118
119 // The ellipse
120 let p = new FPath();
121 p.ellipse(cx,cy,a,b,0,0,2*Math.PI);
122 ctx.strokeStyle = 'black';
123 ctx.lineWidth = 1.5;
124 ctx.stroke(p);
125
126 // An animation, based on the parameterization p(t) = (a cos(t),b sin(t)).
127 // This based on the eccentric angle, so time won't seem to be
128 // constant, but that's OK. This is easier.
129 let t = 2*Math.PI * loopw.curStep / numSteps;
130 let px = a * Math.cos(t) + cx;
131 let py = b * Math.sin(t) + cy;
132
133 p = new FPath();
134 p.moveTo(cx - c,yaxis);
135 p.lineTo(px,py);
136 p.lineTo(cx + c,yaxis);
137 ctx.lineWidth = 0.4;
138 ctx.stroke(p);
139
140 // In this case (unlike most others), the widgets must be explicitly drawn.
141 w1.draw(ctx);
142 w2.draw(ctx);
143 }
144 \end{figput}
145 \caption{Tacks-and-string Ellipse}
146 \label{fig-ellipse-draw}
147 \end{figure}
148
149 \section{Example: Diffusion}
150
151 The concept of diffusion is illustrated by Figure
152 (\ref{fig-boltzmann}). Statistical mechanics and Boltzmann's equation
153 explain concepts like heat transfer and the gas laws by modeling the
154 random motion of many particles. These equations may be difficult to grasp,
155 but an intuitive understanding is not difficult. At time zero, there
156 is some set of particles on the left half of the box, each of which is
157 moving with some randomly distributed momentum. The divider is removed
158 and, over time, the particles distribute themselves more evenly
159 throughout the box.
160
161 \begin{figure}
162 \begin{figput}{diffusion,180bp}[0bp,30bp,done,skip]
163 function diffusion(ctx) {
164
165 // This is an open-ended animation.
166 let wanim = OpenAnimWidget.register(ctx,50,-32,1.0,
167 200, // horizontal size
168 true, // visible
169 10, // time step (ms)
170 10000, // decay
171 false, // steps not visible
172 true, // fast/slow visible
173 true, // pause/run visible
174 true, // time bar visible
175 false, // time bar not grabable.
176 'anim');
177
178 // A button for removing the divider.
179 let wbut = ButtonWidget.register(ctx,-85,32,'Open/Restart','but');
180
181 // Draw the enclosing box.
182 let p = new FPath();
183 p.moveTo(1,2);
184 p.lineTo(300,2);
185 p.lineTo(300,178);
186 p.lineTo(1,178);
187 p.closePath();
188 ctx.lineWidth = 3;
189 ctx.fillStyle = 'black';
190 ctx.strokeStyle = 'black';
191 ctx.stroke(p);
192
193 // These define the box for the particles.
194 let boxleft = 5;
195 let boxright = 150;
196 let boxbot = 4;
197 let boxtop = 175;
198 let boxdivider = 145;
199
200 if ((diffusion.started === undefined) || (wbut.resetState === true))
201 {
202 wbut.resetState = false;
203 wanim.curStep = 0;
204
205 // Allocate 100 dots in the left half of the box.
206 // Each needs a position and direction.
207 diffusion.pos = [];
208 diffusion.dir = [];
209 for (let i = 0; i < 100; i++)
210 {
211 // Position
212 let r = Math.random();
213 let x = boxleft + r*(boxdivider - boxleft - 4);
214
215 r = Math.random();
216 let y = boxbot + r*(boxtop-boxbot)
217 diffusion.pos.push({x: x, y: y});
218
219 // Direction vector. Say each is evenly distributed over
220 // (0,1). That is not physically correct, but that's OK.
221 // To make this better, consider how the balls could bounce
222 // off of each other. That's messy, so I let them pass
223 // through one another, and only consider bouncing off walls.
224 let vx = (Math.random() - 0.50) / 2.0 ;
225 let vy = Math.sqrt(0.25*0.25 - vx*vx);
226 if (Math.random() > 0.50)
227 vy *= -1;
228
229 // Don't let either value be too small. It looks weird.
230 if (Math.abs(vx) < 0.05)
231 {
232 if (vx < 0.0)
233 vx = -0.05;
234 else
235 vx = 0.05;
236 }
237 if (Math.abs(vy) < 0.05)
238 {
239 if (vy < 0.0)
240 vy = -0.05;
241 else
242 vy = 0.05;
243 }
244
245 diffusion.dir.push({x: vx, y: vy});
246 }
247
248 diffusion.started = true;
249 }
250
251 // As noted, we only consider bouncing off walls. Assume that a ball
252 // moves from it's old position to new by the dir vector with each
253 // time step. If that would take the ball outside the rectangle, then
254 // we must consider reflection.
255 let dotR = 3;
256
257 // Draw the "wall" if it's closed.
258 if (wbut.clickState === false)
259 {
260 p = new FPath();
261 p.moveTo(boxdivider,2);
262 p.lineTo(boxdivider,boxtop + 2);
263 ctx.lineWidth = 3;
264 ctx.stroke(p);
265 }
266
267 // This depends on whether the wall is up.
268 let rightEdge = boxdivider - 3;
269
270 if (wbut.clickState === true)
271 rightEdge = 299;
272
273 for (let i = 0; i < diffusion.pos.length; i++)
274 {
275 let pold = diffusion.pos[i];
276 let vold = diffusion.dir[i];
277
278 let pnew = {x: pold.x + vold.x, y: pold.y + vold.y};
279 //console.log(i+ ' ' +pnew.y);
280 if (pnew.y < boxbot)
281 {
282 // Bounced off top edge.
283 // If each step takes 1 unit of time, then it hit the edget at
284 // Actually... be sloppy. I'm not really doing physics; I just
285 // want to demonstrate the FigPut system.
286 // The balls are moving slowly, so only allow them to reflect
287 // at the time of the step divisions.
288 diffusion.dir[i].y *= -1;
289 }
290 if (pnew.y > boxtop)
291 {
292 // Bottom edge bounce.
293 diffusion.dir[i].y *= -1;
294 }
295 if (pnew.x < boxleft)
296 // Left edge bounce.
297 diffusion.dir[i].x *= -1;
298 if (pnew.x > rightEdge - 2)
299 // Right edge bounce.
300 diffusion.dir[i].x *= -1;
301
302 // Redo, after taking reflections into account.
303 vold = diffusion.dir[i];
304 pnew = {x: pold.x + vold.x, y: pold.y + vold.y};
305
306 diffusion.pos[i] = pnew;
307
308 p = new FPath();
309 p.ellipse(pnew.x,pnew.y,dotR,dotR,0,0,2*Math.PI);
310 ctx.fill(p);
311 }
312 }
313 \end{figput}
314 \caption{Diffusion and Boltzmann's Equation}
315 \label{fig-boltzmann}
316 \end{figure}
317
318 \newpage
319
320 \section{Example: Gears}
321
322 Gears like those in Figure (\ref{fig-gear-toy}) might work after a
323 fashion, but it's rare to see such gears in anything other than a
324 child's toy. As a rule, gears take the form shown in Figure
325 (\ref{fig-final-gear}). Why?
326
327 \begin{figure}[b!]
328 \begin{figput}{badgear,130bp}[done,skip]
329 function badgear(ctx) {
330
331 var path1 = new FPath();
332
333 let numTeeth = 17;
334 let cx = 70;
335 let cy = 65;
336 let inR = 40;
337 let outR = 50;
338
339 path1 = new FPath();
340
341 // A dot at the center.
342 path1.ellipse(cx,cy,2,2,0,0,2*Math.PI);
343 ctx.fillStyle = 'black';
344 ctx.fill(path1);
345
346 // The teeth of the gear.
347 path1 = new FPath();
348
349 // One degree, in radians, then 360 and 180 degrees.
350 let d = Math.PI / 180;
351 let d360 = 2 * Math.PI;
352 let d180 = Math.PI;
353
354 let x = cx + inR * Math.cos(0);
355 let y = cy + inR * Math.sin(0);
356 path1.moveTo(x,y);
357
358 let deltaA = Math.PI/numTeeth;
359
360 for (let i = 0; i < numTeeth; i++)
361 {
362 x = cx + inR * Math.cos(2 * i * deltaA + deltaA);
363 y = cy + inR * Math.sin(2 * i * deltaA + deltaA);
364 path1.lineTo(x,y);
365
366 x = cx + outR * Math.cos(2 * i * deltaA + deltaA);
367 y = cy + outR * Math.sin(2 * i * deltaA + deltaA);
368 path1.lineTo(x,y);
369
370 x = cx + outR * Math.cos(2 * i * deltaA + deltaA + deltaA);
371 y = cy + outR * Math.sin(2 * i * deltaA + deltaA + deltaA);
372 path1.lineTo(x,y);
373
374 x = cx + inR * Math.cos(2 * i * deltaA + deltaA + deltaA);
375 y = cy + inR * Math.sin(2 * i * deltaA + deltaA + deltaA);
376 path1.lineTo(x,y);
377 }
378
379 path1.closePath();
380 ctx.lineWidth = 1.5;
381 ctx.stroke(path1);
382
383 // Now the triangular teeth.
384 numTeeth = 21;
385 cx = 230;
386 outR = 60;
387
388 path1 = new FPath();
389 path1.ellipse(cx,cy,2,2,0,0,2*Math.PI);
390 ctx.fill(path1);
391
392 path1 = new FPath();
393
394 x = cx + + inR * Math.cos(0);
395 y = cy + inR * Math.sin(0);
396 path1.moveTo(x,y);
397
398 for (let i = 0; i < numTeeth; i++)
399 {
400 x = cx + outR * Math.cos(i * d360/numTeeth + d180/numTeeth);
401 y = cy + outR * Math.sin(i * d360/numTeeth + d180/numTeeth);
402 path1.lineTo(x,y);
403
404 x = cx + inR * Math.cos((i+1) * d360/numTeeth);
405 y = cy + inR * Math.sin((i+1) * d360/numTeeth);
406 path1.lineTo(x,y);
407 }
408 path1.closePath();
409 ctx.stroke(path1);
410 }
411
412 \end{figput}
413 \caption{Crude Gear Designs}
414 \label{fig-gear-toy}
415 \end{figure}
416
417 Figure (\ref{fig-gear-spoke}) illustrates the fundamental problem of
418 gear design, using a particularly bad design. The ``gears'' here have
419 been reduced to something more like spokes. The gear on the right
420 rotates counter-clockwise at a constant rate and drives the gear on
421 the left. As the gears rotate, the rate of rotation of the gear on the
422 left will not be constant; at some positions, the left gear is nearly
423 stationary and at other positions, it rotates much faster than the
424 gear on the right. In addition, the point of contact slides,
425 generating friction and wear.
426
427 \begin{figure}
428 \begin{figput}{badspokegear,130bp}[done,skip]
429 function badspokegear(ctx) {
430
431 // Two gear-like pinwheels, where the one on the right drives the one on
432 // the left. The idea is to show how the rotation surges, and why something
433 // like involvolute gears are needed.
434 //
435 // Modeling this is surprisingly fiddly. There's no need to make this
436 // fully general, for all possible arrangements, and it's not too bad
437 // if we restrict things a bit.
438 //
439 // In general (too general), suppose that the two sets of spokes have
440 // lengths R1 and R2. Think of the gear on the right driving the
441 // gear on the left, with the gear on the right rotating ccw (under the
442 // usual RH coordinate system). WLOG, assume that the two axles are on the
443 // x-axis. We want to know where the two spokes initially touch "at
444 // the top," but it's actually easier to figure out where the last touch
445 // "at the bottom."
446 //
447 // To simplify, assume that all spokes (on both gears) have the same
448 // length, R. And assume that the centers of these gears are at
449 // (-x,0) and (x,0) so that the centers are 2x appart. Obviously, R > x
450 // for the gears to mesh at all.
451 //
452 // Since the spokes are all the same length, it's easy to see that
453 // The angle of the RH spoke at the top is alpha above the x-axis when
454 // the spokes initally touch, and alpha below the x-axs when they cease
455 // to touch. Here, alpha is defined by
456 // cos(alpha) = x/R.
457 //
458 // Furthermore, let delta be the angle from spoke to spoke, so the
459 // number of spokes is 2 pi / delta. Assume that both gears have the
460 // same number of spokes. Note that delta must be less than 2 alpha
461 // for the spokes to always be in contact. Ideally, I want delta to be
462 // large enough so that no more than one pair of spokes (one on left and
463 // on on right) is ever in contact. Otherwise, it's more messy since
464 // you'd have to figure out which pair of spokes is doing the driving.
465 // In fact, it looks like I want delta = 2 alpha, or to put it another
466 // way, given delta, it follows that alpha = delta / 2.
467 //
468 // Now, think about what happens as the point of contact goes from the
469 // top, where the spoke barely touch, downward. The point of contact
470 // stays on the top of the left spoke and slides down on the right spoke.
471 // What you have is a triangle on the left with hypoteneuse R, and a
472 // triangle on the right with hypoteneuse r. We need to determine r.
473 // Let beta be the angle of the right spoke above the x-axis. beta
474 // grows linearly with time, and is fully known...actually, beta
475 // *shrinks* if we think of it as the angle of the right spoke above
476 // the x-axis.
477 //
478 // Let c be the x-coordinate of the point of contact, and let x1 be
479 // the distance from c to -x (the left axle) and x2 be the distance
480 // from c to +x (the right axle). We must have
481 // R^2 - x1^2 = r^2 - x2^2
482 // since the left and right triangles share the same vertical leg.
483 // And x1 + x2 = 2x by construction. The third equation we need
484 // is cos(beta) = x2/r or x2 = r cos(beta).
485 //
486 // Solve these three equations for x1, x2 and r in terms of R and x.
487 // First, use x1 = 2x - x2. Substitute:
488 // R^2 - x1^2 = r^2 - x2^2
489 // R^2 - (2x-x2)^2 = r^2 - x2^2
490 // R^2 - 4x^2 + 4x*x2 - (x2)^2 = r^2 - x2^2
491 // R^2 - 4x^2 + 4x*x2 = r^2
492 //
493 // Now use x2 = r cos(beta) and use C = cos(beta) for brevity:
494 // R^2 - 4x^2 + 4x*x2 = r^2
495 // R^2 - 4x^2 + 4x*(rC) = r^2
496 // r^2 - 4Cx r + 4x^2 - R^2 = 0.
497 // Solve for r by quadatic equation:
498 // r = (1/2) [ 4Cx \pm \sqrt{ 16C^2x^2 - 4(4x^2-R^2) } ]
499 // r = 2Cx \pm \sqrt{ 4C^2x^2 - 4x^2+ R^2 }
500 // r = 2Cx \pm \sqrt{ 4x^2(cos^2(beta) - 1 ) + R^2 }
501 // r = 2Cx \pm \sqrt{ -4x^2 sin^2(beta) + R^2 }
502 //
503 // Aside: note that the discriminant is always postive since R > x.
504 // I'm not sure what the two solutions here might "mean."
505 //
506 // This tells us what is going on from the point when the spokes touch
507 // at the top until you reach the point where they are aligned along the
508 // x-axis. However, we need the angle on the left -- that was the
509 // whole point. We have angle beta on the right, and we want to know
510 // the angle, gamma, on the left.
511 //
512 // We have cos(gamma) = x1/R, where gamma is measured upwards from the
513 // x-axis to the spoke in contact on the left gear (like normal).
514 //
515 // Now do something similar as the point of contact goes below the
516 // x-axis. It's the same basic calculation, except that the tip of the
517 // right spoke is in contact somewhere along the left spoke.
518 // Left and right are reversed.
519 //
520 // We still have x1 + x2 = 2x but now R^2 - x2^2 = r^2 - x1^2, and
521 // cos(beta) = x2/R. It's the same basic game. We get.
522 //
523 // R^2 + 4x^2 - 4x*x2 = r^2
524 // just as before. But now use x2 = R cos(beta) (R, not r) and it's
525 // a simpler problem:
526 // R^2 - 4x^2 + 4x*x2 = r^2
527 // R^2 - 4x^2 + 4x R cos(beta) = r^2
528 // becomes
529 // r = \pm\sqrt{ R^2 - 4x^2 + 4x R cos(beta) }
530 //
531 // BUG: The calculation above treats the spokes as geometric lines, with zero
532 // thickness. Ideally, I should take the width of the lines into account.
533
534 // The presence of this widget means that this is an animation.
535 // The code here will be called on a regular schedule.
536 let stepsPerRev = 500;
537 let startStep = 0;
538 let timeStep = 20;
539
540 let w = LoopAnimWidget.register(ctx,
541 -LoopAnimWidget.Radius,LoopAnimWidget.Radius + LoopAnimWidget.TopHeight,0.75,
542 true,stepsPerRev,startStep,timeStep,
543 true,true,true,true,true,"wigname");
544
545 // BUG: I messed up when I wrote this and inadvertantly did all the
546 // measurements to the wrong scale. Thus, I have to undo my mistake.
547 // The real fix is to change all the constants below so that this
548 // scale() isn't necessary.
549 let mistakeT = ctx.getTransform();
550 ctx.scale(0.5,0.5);
551
552 // The two gears are on opposite sides of this vertical line.
553 let xZero = 300;
554
555 // You can change the number of teeth, but the surging is most apparent
556 // with four teeth (which is the minimum geometrically possible given
557 // the algebra. Somewhere around 6 or 7 teeth it becomes hard to see.
558 // BUG: five teeth generates some kind of "jump" in the animation.
559 // Not sure why.
560 let numTeeth = 4;
561 let spokeLength = 100;
562
563 // The angle between spokes.
564 let delta = 2*Math.PI/numTeeth;
565
566 // Spoke radius and thickness.
567 let R = spokeLength;
568 let spokeWidth = 2;
569
570 // Distance of each spoke axis from the center line.
571 // I want the top pair of spokes to make contact at the same instant
572 // that the bottom pair of spokes ceases contact. That requires
573 let x = R * Math.cos(delta/2);
574
575 // Draw the spokes on the right. These are the drivers, so the angle rises
576 // linearly with time.
577 let cx = (xZero + x);
578 let cy = 140;
579
580 var path1 = new FPath();
581
582 // A dot at the center, probably not necessary.
583 path1.ellipse(cx,cy,2.0*spokeWidth,2.0*spokeWidth,0,0,2*Math.PI);
584 ctx.fill(path1);
585
586 // Angle by which the gear has rotated, based on the step of the animation.
587 let rotA = w.curStep * 2 * Math.PI / stepsPerRev;
588
589 for (let i = 0; i < numTeeth; i++)
590 {
591 path1 = new FPath();
592
593 let angle = i*delta + rotA;
594 while (angle < 0)
595 angle += 2 * Math.PI;
596 while (angle > 2*Math.PI)
597 angle -= 2 * Math.PI;
598
599 path1.moveTo(cx,cy);
600 let x = cx + R * Math.cos(angle);
601 let y = cy + R * Math.sin(angle);
602 path1.lineTo(x,y);
603
604 ctx.strokeStyle = "black";
605 ctx.lineWidth = spokeWidth;
606 ctx.stroke(path1);
607 }
608
609 // Now the left, driven, set of spokes.
610 cx = (xZero - x);
611
612 // Figure out which of the spokes on the right gear is the one in contact
613 // and doing the driving. It's the one whose angle relative to the
614 // x-axis is between delta/2 above and delta/2 below the axis.
615 // To put it another way, its angle is in the range pi\pm delta/2.
616 // This could have been noted in the loop above.
617 let contactAngle = 0.0;
618 for (let i = 0; i < numTeeth; i++)
619 {
620 let angle = i*delta + rotA;
621 while (angle < 0)
622 angle += 2 * Math.PI;
623 while (angle > 2*Math.PI)
624 angle -= 2 * Math.PI;
625
626 if ((angle < Math.PI + delta/2) && (angle > Math.PI - delta/2))
627 {
628 contactAngle = angle;
629 break;
630 }
631 }
632
633 // contactAngle is the angle of the right gear's "contact spoke," but
634 // measured from the right. I want beta (in the notation above), measured
635 // from the left side, to put it in the range [-delta/2,+delta/2].
636 contactAngle = Math.PI - contactAngle;
637
638 var gamma = 0;
639 if (contactAngle >= 0)
640 {
641 // The point of contact is above the x-axis. Slightly messier case.
642 let beta = contactAngle;
643 let disc = R*R - 4*x*x*Math.sin(beta)*Math.sin(beta);
644 let root = Math.sqrt(disc);
645
646 // Conceptually, I'm not sure why, but this seems to be the right
647 // choice -- minus, not plus.
648 let r = 2 * Math.cos(beta) * x - root;
649
650 let x2 = r * Math.cos(beta);
651 let x1 = 2 * x - x2;
652
653 // I didn't address this in the long comment above, but
654 // (x1,sqrt(R^2-x1^2)) is the end-point of the left spoke in
655 // contact with the right spoke. The angle for this spoke is thus
656 // gamma, where cos(gamma) = x1/R.
657 gamma = Math.acos(x1/R);
658 }
659 else
660 {
661 // The point of contact is below the x-axis, hence the minus to
662 // make beta positive.
663 let beta = -contactAngle;
664 let disc = R*R + 4*x*x - 4*x*R*Math.cos(beta);
665 let r = Math.sqrt(disc);
666
667 let x2 = R * Math.cos(beta);
668 let x1 = 2 * x - x2;
669
670 gamma = 2*Math.PI - Math.acos(x1/r);
671 }
672
673 // A dot at the center, probably not necessary.
674 path1 = new FPath();
675 path1.ellipse(cx,cy,2.0*spokeWidth,2.0*spokeWidth,0,0,2*Math.PI);
676 ctx.fill(path1);
677
678 // Draw the left spokes, based on gamma.
679 rotA = -w.curStep * 2 * Math.PI / stepsPerRev;
680
681 for (let i = 0; i < numTeeth; i++)
682 {
683 path1 = new FPath();
684
685 path1.moveTo(cx,cy);
686 let x = cx + R * Math.cos(i*delta + gamma);
687 let y = cy + R * Math.sin(i*delta + gamma);
688
689 path1.lineTo(x,y);
690
691 ctx.lineWidth = spokeWidth;
692 ctx.stroke(path1);
693 }
694
695 // BUG: Undo the above fix of my scaling mistake.
696 ctx.setTransform(mistakeT);
697 }
698 \end{figput}
699 \caption{Maybe the Worst Possible Gears?}
700 \label{fig-gear-spoke}
701 \end{figure}
702
703 Understanding how to design gears without the kind of surging motion
704 and wear inherent in the gears of Figure (\ref{fig-gear-spoke})
705 explains why nearly all modern gears take the form of Figure
706 (\ref{fig-final-gear}). The most glaring problem with the
707 spoke-like gears is the way their motion varies -- imagine riding in a
708 car with a gear-train based on such gears!
709
710 Gears typically have what's called \emph{conjugate action},
711 meaning that the ratio of their rates of rotation is constant,
712 with no surging or lagging. Sometimes this is also called the
713 \emph{fundamental law of gearing}, although it would be more accurate
714 to call it a ``commonly desired feature,'' rather than a ``law.''
715 Arranging the teeth of gears so that they have conjugate action is
716 surprisingly tricky.
717
718 \subsection{The Involute}
719
720 Figure (\ref{fig-basic-gear-constraints}) shows a cam and a lever-arm
721 pushing against each other, causing them to rotate about their
722 respective axes. Imagine that the cam rotates counter-clockwise,
723 pushing the arm downwards. There are several crucial observations:
724 \begin{enumerate}[itemsep=-1pt]
725 \item The two curves must be tangent at the point of contact.
726 \item The force from one part to the other must be directed along a
727 line perpendicular to the two curves at the point of contact. Call
728 this the \emph{line of action}.
729 \item Let $P$ be point where the line of action intersects the line
730 connecting the two centers of rotation. This is called the
731 \emph{pitch point}. The instantaneous ratio of
732 the two rates of rotation is equal to the ratio of the distances
733 from $P$ to each of the centers of rotation.
734 \end{enumerate}
735 In conclusion, if two gears are to have conjugate action, then the
736 pitch point must be fixed.
737
738 \begin{figure}
739 \begin{figput}{gearconstraints,120bp}[done,skip]
740 function gearconstraints(ctx) {
741
742 // A static figure. No widgets.
743 //
744 // I wrote this before I changed the framework to assume a RH coordinates
745 // system. Instead of messing around changing the values below, each path
746 // is reflected and translated, much like a transformation matrix.
747
748 // Cam center.
749 let cax = 250;
750 let cay = 80;
751 let ra = 5;
752
753 let p = new FPath();
754 p.ellipse(cax,cay,ra,ra,0,0,2*Math.PI);
755 ctx.strokeStyle = 'black';
756 ctx.lineWidth = 0.4;
757
758 p = p.reflectX();
759 p = p.translate(new Point2D(0,120));
760
761 ctx.stroke(p);
762
763 // Cam itself
764
765 // Right upper
766 let cs = 15; // space to right of axis
767 let h1 = 60; // height above
768 let tan1 = 25; // tightness of tangents
769 let tan2 = 25;
770
771 p = new FPath();
772 p.moveTo(cax+cs,cay);
773 p.bezierCurveTo(cax+cs,cay - tan1,
774 cax-cs + tan2,cay-h1,
775 cax-cs,cay-h1);
776
777 // left upper
778 let h2 = 70; // how far left
779 let t1 = 20; // thickness of arm
780 tan1 = 4;
781 tan2 = 3;
782 p.bezierCurveTo(cax-cs-tan1,cay - h1,
783 cax-cs - h2,cay - h1,
784 cax-cs - h2,cay - h1 + t1);
785
786 // Lower left
787 let h3 = 40; // how far back right
788 p.bezierCurveTo(cax-cs-h2,cay - h1 + t1 + tan2,
789 cax-cs - h2,cay - h1 + 2*t1,
790 cax-cs - h2 + h3,cay - h1 + 2*t1);
791
792 // Inner concave
793 tan1 = 20;
794 tan2 = 20;
795 p.bezierCurveTo(cax-cs-h2 + h3 + tan1,cay - h1 + 2*t1,
796 cax-cs,cay - tan2,
797 cax-cs,cay);
798
799 // lower left below
800 tan1 = 8;
801 tan2 = 8;
802 p.bezierCurveTo(cax-cs,cay + tan1,
803 cax-tan2,cay + cs,
804 cax,cay+cs);
805
806 // lower right below
807 // BUG: It's hard to get these curves to meet smoothly. Need a better 'close'.
808 tan1 = 17;
809 tan2 = 10;
810 p.bezierCurveTo(cax + tan1,cay + cs,
811 cax + cs,cay - tan2,
812 cax + cs,cay);
813
814 ctx.lineWidth = 2.0;
815
816 p = p.reflectX();
817 p = p.translate(new Point2D(0,120));
818
819 ctx.stroke(p);
820
821 // Now something similar for the long arm.
822 // The easiest way to do this is to draw it horizontal, but rotate all the
823 // points by some angle so that the arm touches the cam.
824 cax = 30
825 cay = 100;
826
827 p = new FPath();
828 p.ellipse(cax,cay,ra,ra,0,0,2*Math.PI);
829 ctx.strokeStyle = 'black';
830 ctx.lineWidth = 0.4;
831
832 p = p.reflectX();
833 p = p.translate(new Point2D(0,120));
834
835 ctx.stroke(p);
836
837 // top right
838 cs = 12; // half thickness
839 let L = 150; // length
840
841 p = new FPath();
842 tan1 = 10;
843 tan2 = 10;
844 p.moveTo(cax,cay + cs);
845 p.bezierCurveTo(cax + tan1,cay + cs,
846 cax + L - tan2,cay +cs,
847 cax + L,cay + cs);
848
849 // lower right
850 tan1 = 6;
851 tan2 = 6;
852 p.bezierCurveTo(cax + L + tan1,cay +cs,
853 cax + L + cs,cay + tan2,
854 cax + L + cs,cay);
855
856 // upper right
857 p.bezierCurveTo(cax + L + cs,cay - tan1,
858 cax + L + tan2,cay - cs,
859 cax + L,cay - cs);
860
861 // top
862 p.bezierCurveTo(cax + L - tan1,cay - cs,
863 cax + tan2,cay - cs,
864 cax,cay - cs);
865
866 // upper left
867 p.bezierCurveTo(cax - tan1,cay - cs,
868 cax - cs,cay - tan2,
869 cax - cs,cay);
870
871 // lower left to close
872 p.bezierCurveTo(cax - cs,cay + tan1,
873 cax - tan2,cay + cs,
874 cax,cay + cs);
875
876 // Rotate the entire thing
877 let a = -12 * Math.PI / 180; // angle to rotate
878 let p2 = p.rotateAbout(a,new Point2D(cax,cay));
879
880 ctx.lineWidth = 2.0;
881
882 p2 = p2.reflectX();
883 p2 = p2.translate(new Point2D(0,120));
884
885 ctx.stroke(p2);
886 }
887 \end{figput}
888 \caption{Basic Constraints on Gears}
889 \label{fig-basic-gear-constraints}
890 \end{figure}
891
892 See Figure (\ref{fig-basic-involute}).
893 Imagine a string wrapped around the circle, with one end fixed to the
894 circle and a pencil at the other end. As the string unwraps from the
895 circle, the pencil traces out a
896 curve called the involute. The line determined by the string is
897 obviously tangent to the circle at the point at which it meets the circle. The
898 line is also perpendicular to the involute because, at each
899 instantaneous point of rotation, the involute is locally an arc of the
900 circle formed by the string. For a circle of radius $r$ centered at the
901 origin, the involute can be parameterized by $i(t)=(i_x(t),i_y(t))$, where
902 \begin{eqnarray*}
903 i_x(t) &=& r (\cos t + t \sin t) \\
904 i_y(t) &=& r (\sin t - t \cos t)
905 \end{eqnarray*}
906 As we will see, the notable thing about the involute is that when gear
907 teeth take the form of an involute, the pitch point is constant
908 throughout the gears' motion.
909
910 \begin{figure}[b!]
911 \begin{figput}{basicinvolute,140bp}[done,skip]
912 // An extra function to define the involute.
913 function invo(t) {
914
915 // Basically, if you have a circle of radius a, the parametric form is
916 // x(t) = a (cos t + t sin t)
917 // y(t) = a (sin t - t cos t)
918 // The parameterization starts with t = 0, then runs as an angle in radians.
919
920 // These values copied from below.
921 let cx = 160;
922 let cy = 52;
923 let a = 50;
924
925 let c = Math.cos(t);
926 let s = Math.sin(t);
927
928 return new Point2D( cx + a*(c + t*s), cy + a*(s - t*c));
929 }
930
931 function basicinvolute(ctx) {
932
933 // A looping animation that draws an involute. The string unwraps
934 // and re-wraps in a loop. Note the doubling of numSteps since I
935 // want back-and-forth action.
936 let numSteps = 100;
937 let loopw = LoopAnimWidget.register(ctx,-30,55,0.85,
938 true, // visible
939 2*numSteps, // steps per loop
940 0, // starting step
941 20, // ms time step
942 //false,false,false,false,false, // nothing is visible
943 true,true,true,true,true, // Everything visible
944 'loop');
945
946 let cx = 160;
947 let cy = 52;
948 let r = 50;
949
950 // circle
951 let p = new FPath();
952 p.ellipse(cx,cy,r,r,0,0,2*Math.PI);
953 ctx.strokeStyle = 'black';
954 ctx.lineWidth = 0.4;
955 ctx.stroke(p);
956
957 // And a dot at the center.
958 p = new FPath();
959 p.ellipse(cx,cy,2,2,0,0,2*Math.PI);
960 ctx.fillStyle = 'black';
961 ctx.fill(p);
962
963 // Draw the involute by converting to a bezier.
964 // The level of ``unwrap'' is determined by the number of steps of
965 // the animation.
966 let t = 2 * Math.abs((loopw.curStep - numSteps) / numSteps);
967 let segs = Math.ceil(15 * t);
968 p = FPath.parametricToBezier(invo,0,t,segs);
969 ctx.lineWidth = 1.2;
970 ctx.stroke(p);
971
972 // The string goes from the end of the involute to a point tangent
973 // to the circle. So, I have a circle centered at
974 // (c_x,c_y) and a point p = (p_x,p_y) = end-point of involute, and
975 // I want the point on the circle such that the line from the point on
976 // the circle to p is tangent to the circle. The circle is parameterized
977 // by (c_x,c_y) + r(cos a,sin a), (a varies) so the tangent to the circle is
978 // parameterized by r(-sin a,cos a). I need such a tangent vector that points
979 // to p. Let t(a) = r(-sin a,cos a) and c(a) = r(cos a,sin a). I need to
980 // find a such that c(a) + s t(s) = p, for some s. Thus, I need to solve
981 // (c_x + r cos a - s r sin a,c_y + r sin a + s r cos a) = (p_x,p_y)
982 // for a and s (although I don't really care about s). We have
983 // c_x + r cos a - s r sin a = p_x implies
984 // s = ( c_x + r cos a - p_x) / r sin a
985 // Plugging into the other coordinate, we get
986 // p_y = c_y + r sin a + s r cos a
987 // p_y = c_y + r sin a + r cos a ( c_x + r cos a - p_x) / r sin a
988 // p_y = c_y + r sin a + cos a ( c_x + r cos a - p_x) / sin a
989 //
990 // BLAH. That is a mess. Easier is to do it by construction.
991 // We have a circle centered at C and a point P. Let D be the midpoint
992 // of line line CP. The circle about D passing through C and P meets the
993 // circle around C at two points, E and F. The line from C to E (or to F)
994 // is a right angle since the angle is ``inscribed'' in the circle about D.
995 // This is a general fact, that if you take two points that are opposite
996 // each other in a circle (C and P in my example) and *any* other point
997 // on that circle, then the angle formed by the two opposite points and
998 // that other point is a right angle.
999 // If that is a right angle, then the line from P to E (or to F) is tangent
1000 // to the circle.
1001 //
1002 // Moral of the story...We have circle centered at (c_x,c_y) and p=(p_x,p_y),
1003 // the end-point of involute. The line from p tangent to the circle is
1004 // obtained by defining d=(d_x,d_y) as the midpoint of c and p. The
1005 // intersection of the circle around d with the circle around c is the
1006 // point in question.
1007 //
1008 // I've reduced to the problem of finding the points of intersection of two
1009 // circles. We have
1010 // (x-c_x)^2 + (y-c_y)^2 = r_c^2
1011 // (x-d_x)^2 + (y-d_y)^2 = r_d^2
1012 // Subtract the second from the first to obtain
1013 // (x-c_x)^2 - (x-d_x)^2 + (y-c_y)^2 - (y-d_y)^2 = r_c^2 - r_d^2
1014 // Expand and collect:
1015 // x^2-2xc_x+c_x^2 - x^2+2xd_x-d_x^2 + y^2-2yc_y+c_y^2 - y^2+2yd_y-d_y^2 =
1016 // r_c^2 - r_d^2
1017 // -2xc_x+c_x^2 +2xd_x-d_x^2 - 2yc_y+c_y^2 +2yd_y-d_y^2 = r_c^2 - r_d^2
1018 // 2x(d_x-c_x) + 2y(d_y-c_y) + c_x^2 -d_x^2 +c_y^2 -d_y^2 = r_c^2 - r_d^2
1019 // 2x(d_x-c_x) + 2y(d_y-c_y) = (r_c^2-r_d^2) + (c_x^2-d_x^2) + (c_y^2 -d_y^2)
1020 // Solve for y (say):
1021 // y = x(c_x-d_x) / 2(d_y-c_y) +
1022 // [ (r_c^2-r_d^2) + (c_x^2-d_x^2) + (c_y^2 -d_y^2) ] / 2(d_y-c_y)
1023 // and plug this back into the original equation for the circle and you
1024 // can solve for x. First, write the above eqn for y as
1025 // y = x(c_x-d_x) / D + r_m / D
1026 // = [ x(c_x-d_x) + r_m ] / D
1027 // where r_m means ``r-mess'' and D is for ``denominator.''
1028 // (x-c_x)^2 + (y-c_y)^2 = r_c^2
1029 // (x-c_x)^2 + [ ( x(c_x-d_x)+ r_m ) / D - c_y ]^2 = r_c^2
1030 // (x-c_x)^2 + ( x(c_x-d_x)+ r_m )^2 / D^2 - c_y ]^2 = r_c^2
1031 // Etc. In theory, this is a quadratic in x, but wow.
1032 //
1033 // That is another mess. Back up a bit, and consider the general case
1034 // of the intersection of two circles, c and d.
1035 // Let D = distance between centers and P be the point of intersection.
1036 // Draw a line between the centers and two triangles, one from center c to
1037 // P and then perpendicular to the line betwene centers, and the other
1038 // triangle similar, but in circle d. Let E be the point where the
1039 // perpendicular leg of the triangles intersects the line between centers.
1040 // We have distances a and b, a from center of C to E, and b from center
1041 // of d to E. Let h be the height of this perpendicular leg. We have
1042 // D = a + b, a^2 + h^2 = r_c^2 and b^2 + h^2 = r_d^2. Solve for a and b.
1043 // This is really the same is the big messy thing, but easier to follow.
1044 //
1045 // FORGET ABOUT THE ABOVE. THIS IS THE WAY TO DO IT.
1046 // Back way up to the very begining and reconsider the whole thing with
1047 // simpler assuptions. Suppose that the circle is centered at the origin,
1048 // so we can ignore (c_x,c_y). Assume also that the point is on the
1049 // x-axis so that p = (p_x,p_y) = (p_x,0). Now the circle is
1050 // C(a) = r (cos a, sin a)
1051 // C'(a) = r (-sin a, cos a).
1052 // We want the line through C(a) pointing in the C'(a) direction to
1053 // pass through p. That is, we require a solution (in t and a) to
1054 // C(a) + t C'(a) = p
1055 // r cos a - r t sin a = p_x and r sin a + r t cos a = 0.
1056 // So t = - sin a / cos a = - tan a. Then
1057 // r cos a + r sin^2 a / cos a = p_x
1058 // r cos^2a + r sin^2 a = p_x cos a
1059 // r = p_x cos a
1060 // THAT we can solve for a. We get this solution, but then have to shift
1061 // and rotate. Rotate the entire plane by the angle that p is relative to
1062 // the x-axis. Then shift to move the origin of the circle to (c_x,c_y).
1063 //
1064 // BUG: This entire mess belongs in some geometry module, preferably with
1065 // a complete discussion of the math.
1066
1067 let P = invo(t);
1068
1069 // This is p_x in the analysis above.
1070 let Pd = Math.sqrt((P.x - cx)**2 + (P.y - cy)**2);
1071
1072 // There are two possible solutions for r = p_x cos a or
1073 let a = Math.acos(r/Pd);
1074
1075 // Now have a solution that's valid for P on the x-axis. Rotate (Pd,0) to P.
1076 // This has the effect of rotating C(a) (with the a just determined this
1077 // would be the tangent point if P were on the x-axis and C were centered
1078 // at the origin) through an angle b, determined by tan b = P_x/P_y.
1079 // But we want this relative to (cx,cy), so shift.
1080 let b = Math.atan2(P.y-cy,P.x-cx);
1081
1082 // The point we want is now C(a+b), then translated by (cx,cy).
1083 let E = new Point2D(r*Math.cos(a+b)+cx,r*Math.sin(a+b)+cy);
1084
1085 p = new FPath();
1086 p.moveTo(P.x,P.y);
1087 p.lineTo(E.x,E.y);
1088 ctx.lineWidth = 0.8;
1089 ctx.stroke(p);
1090
1091 }
1092 \end{figput}
1093 \caption{The Involute of a Circle}
1094 \label{fig-basic-involute}
1095 \end{figure}
1096
1097 Figure (\ref{fig-constant-pp}) shows two disks acting as gears by
1098 simple friction. The circle of each such disk is
1099 called the \emph{pitch circle} (where they come in contact is the
1100 pitch point). The centers of these disks are joined
1101 by the \emph{line of centers}, and the distance between these centers
1102 is the \emph{center distance}. Now imagine two slightly smaller and
1103 concentric circles, called the \emph{base circles}. These base circles
1104 will be used to form involutes, and these involutes will be the
1105 profiles of the gear teeth.
1106
1107
1108 \begin{figure}
1109 \begin{figput}{constpp,140bp}[done,skip]
1110 function constpp(ctx) {
1111
1112 // A static figure, no interaction.
1113 let rc = 60;
1114 let rd = 40;
1115 let y = 70;
1116
1117 let c = new Point2D(100,y);
1118 let d = new Point2D(c.x + rc+rd,y);
1119
1120 // Pitch circles
1121 let p = new FPath();
1122 p.ellipse(c.x,c.y,rc,rc,0,0,2*Math.PI);
1123 ctx.strokeStyle = 'black';
1124 ctx.lineWidth = 1.5;
1125 ctx.stroke(p);
1126
1127 p = new FPath();
1128 p.ellipse(d.x,d.y,rd,rd,0,0,2*Math.PI);
1129 ctx.strokeStyle = 'black';
1130 ctx.lineWidth = 1.5;
1131 ctx.stroke(p);
1132
1133 // Base circles
1134 let s = 0.80;
1135 p = new FPath();
1136 p.ellipse(c.x,c.y,s*rc,s*rc,0,0,2*Math.PI);
1137 ctx.strokeStyle = 'black';
1138 ctx.lineWidth = 0.4;
1139 ctx.stroke(p);
1140
1141 p = new FPath();
1142 p.ellipse(d.x,d.y,s*rd,s*rd,0,0,2*Math.PI);
1143 ctx.strokeStyle = 'black';
1144 ctx.lineWidth = 0.4;
1145 ctx.stroke(p);
1146
1147 ctx.font = '10px san-serif';
1148 ctx.fillStyle = 'black';
1149
1150 drawText(ctx,'base circle', c.x,c.y,-4,0);
1151 drawText(ctx,'pitch circle', d.x,c.y+rd+6,0,0);
1152 }
1153 \end{figput}
1154 \caption{Base Circle and Pitch Circle}
1155 \label{fig-constant-pp}
1156 \end{figure}
1157
1158
1159 \begin{figure}[b!]
1160 \begin{figput}{moveinvo,200bp}[done,skip]
1161 // At one point, I was making a small manual adjustment on the figure
1162 // placement here. I did this by wrapping all the drawing
1163 // (after the \useasbounding box) with
1164 // \begin{scope}[shift={(40bp,0bp)}]
1165 // then \end{scope} just before \end{tikzpicture}
1166
1167 function moveinvo(ctx) {
1168
1169 // Similar to above, but don't draw the pitch circles, and only a part
1170 // of the base circles is drawn, and they're larger. There is also
1171 // a line for the line of action and an animation to show what the
1172 // point of contact does over time. OK, so not that similar!
1173
1174 let numSteps = 1000;
1175 let loopw = LoopAnimWidget.register(ctx,-80,100,1.0,
1176 true, // not hidden
1177 numSteps, // steps per loop
1178 0, // starting step
1179 10, // ms time step
1180 true,true,true,true,true,
1181 'loop');
1182
1183 let rc = 80;
1184 let rd = 60;
1185 let y = 100;
1186 let s = 35;
1187
1188 let c = new Point2D(90,y);
1189 let d = new Point2D(c.x + rc+rd +s,y);
1190
1191 // Base circles
1192 p = new FPath();
1193
1194 // I played around, trying to show only portions of the disks so as to
1195 // save space, but it doesn't look right. In some ways, that
1196 // simplifies things.
1197 p.ellipse(c.x,c.y,rc,rc,0,0,2*Math.PI);
1198 ctx.strokeStyle = 'black';
1199 ctx.lineWidth = 1.0;
1200 ctx.stroke(p);
1201
1202 p = new FPath();
1203 p.ellipse(d.x,d.y,rd,rd,0,0,2*Math.PI);
1204 ctx.strokeStyle = 'black';
1205 ctx.lineWidth = 1.0;
1206 ctx.stroke(p);
1207
1208 /* I was going to just draw these arcs, but better to do the
1209 // whole cirles.
1210 //In fact, defer drawing this. I want the entire wedge to turn.
1211 // This arc is centered at (0,0).
1212 let cVisAngle = 4*Math.PI/8;
1213 p = FPath.arcToBezierNEW(rc,-cVisAngle,cVisAngle);
1214 p = p.translate(c);
1215 ctx.lineWidth = 2.0;
1216 ctx.stroke(p);
1217
1218 let dVisAngle = 5*Math.PI/8;
1219 p = FPath.arcToBezierNEW(rd,dVisAngle,-dVisAngle);
1220 p = p.translate(d);
1221 ctx.lineWidth = 2.0;
1222 ctx.stroke(p);
1223 */
1224
1225 // The line of action.
1226 // This involves another calculation of tangent lines. See Graphics Gems I,
1227 // p. 7 and Figure 8. Use similar triangles. We have two distances,
1228 // x_c and x_d from the respective centers of the circles to the point
1229 // where the desired line intersects the line connecting the centers.
1230 // We have x_c + x_d = D = distance between centers, and by
1231 // similar triangles r_c/x_c = r_d/x_d. A little algebra gives
1232 // x_c = r_c D / (r_c + r_d).
1233 //
1234 // We now have one point that must be on the line, and we go through the
1235 // same rigmarole as above to find the line tangent to a circle. The only
1236 // difference is that we've chosen the point through which the circle must
1237 // pass in such a way that the resulting line will be tangent to both
1238 // circles if it's tangent to either of them.
1239 //
1240 // As above, make the simplifying assumption that circle C is centered
1241 // at the origin. Then do a rotate and translate at the end.
1242 let D = Math.sqrt((c.x-d.x)**2 + (c.y-d.y)**2);
1243 let xc = rc * D / (rc + rd);
1244
1245 // We are working (for now) as though circle C is centered at the origin.
1246 // So this is the point we want.
1247 let M = new Point2D(xc,0);
1248
1249 // As in the earlier case, where I did the involute, we get the tangent.
1250 // The difference is that the point is now M, not P, as it was above.
1251 let Md = Math.sqrt((M.x - c.x)**2 + (M.y - c.y)**2);
1252 let a = Math.acos(rc/Md);
1253 let b = Math.atan2(M.y,M.x);
1254 let E = new Point2D(rc*Math.cos(-a+b)+c.x,rc*Math.sin(-a+b)+c.y);
1255
1256 // The above draws from circle C to the central point M, but I need to
1257 // extend the line all the way to the other circle. So I need to know where
1258 // this line intersects that circle. Recall that M was found by similar
1259 // triangles. The angle of the tangent point relative to the circles' centers
1260 // is the same in both cases, although for the circle on the right, we
1261 // have to adjust by pi.
1262 b += Math.PI;
1263 let F = new Point2D(rd*Math.cos(-a+b)+d.x,rd*Math.sin(-a+b)+d.y);
1264
1265 p = new FPath();
1266 p.moveTo(E.x,E.y);
1267 p.lineTo(F.x,F.y);
1268 ctx.lineWidth = 0.6;
1269 ctx.stroke(p);
1270
1271 // The above draws the more or less static setup. Now I want to draw a
1272 // particular point on the line of action, and let it move as the disks
1273 // rotate, tracing out a pair of involutes.
1274 //
1275 // Use M for the particular point along the line, which is detemined
1276 // by t, using a linear parameterization of the line E to F.
1277 // This value is what determines the frame of the animation.
1278 let t;
1279 if (loopw.curStep < numSteps/2)
1280 t = 2* loopw.curStep/numSteps;
1281 else
1282 t = 2 *(numSteps - loopw.curStep)/numSteps;
1283
1284 M = new Point2D(E.x + t*(F.x-E.x),E.y + t*(F.y-E.y));
1285
1286 p = new FPath();
1287 p.ellipse(M.x,M.y,1.5,1.5,0,0,2*Math.PI);
1288 ctx.fillStyle = 'black';
1289 ctx.fill(p);
1290
1291 // I need to know the total size of the tooth. So I need the value for
1292 // t at which the tooth will barely clear the opposing gear. The value
1293 // I am looking for has nothing to do with the current point of contact,
1294 // and is always the same (which is sort of the point). Scale down the
1295 // entire picture and find t for which the distance of involute(t) from
1296 // the center of the left disk is equal to the distance between the
1297 // edges of the two disks.
1298 //
1299 // BUG: A common problem is that lines have thickness. If you want line A
1300 // to barely touch line B, then thicknesses matter. The strictly correct way
1301 // to deal with this is probably to treat lines as filled rectangles (or
1302 // quadrilaterals more generally). This general philisophy is one way to
1303 // handle stuff like arrowheads. Another way might be to allow stroking
1304 // the line on one side of its geometric definition or the other.
1305 // I may have mentioned this issue before.
1306 //
1307 // See above. rc and rd are the two disks' radii and the centers at c and d.
1308 // The distance we care about is d.x-c.x-rd before scaling. Subtract off
1309 // a hair to take into account line thicknesses. Scaling then gives:
1310 let toothD = (d.x-c.x-rd - 2) / rc;
1311
1312 // And the value that brings the unit involute out to this distance.
1313 let toothT = Numerical.newton(solveToothD,0.5,0,3,toothD,0.00001);
1314
1315 // For circle C, we have an involute extending out to M.
1316 // The standard parameterization of the involute assumes that the point
1317 // starts at the x-axis, and that is not true here. The ``point of initial
1318 // contact'' with the base circle varies, and that is sort of the point
1319 // for gear design. At any rate, the usual parameterization is
1320 // x(a) = r (cos a + a sin a)
1321 // y(a) = r (sin a - t cos a)
1322 // What we need to do is to add some constant to a so as to shift
1323 // the involute -- effectively rotate it around the center of the circle.
1324 //
1325 // The distance from M to E is how much string wraps around the circle C.
1326 // This determines the point of initial contact. Let d_M = |M-E|.
1327 // When wrapped around the circle, this corresponds to an angle d_M/r_c.
1328 // It wraps from the point E, and that point is at angle -a+b relative to
1329 // the x-axis. So the adjustment we need to make is a_M = d_M/r_c +a-b.
1330 // There's also a pi adjustment due to LH coordinates.
1331 //
1332 // In addition, we need to know at what value of a (as argument to the
1333 // parameterization) the involute reaches M. THAT is not so easy since it
1334 // amounts to inverting the involute. We want to find t such that
1335 // involute(t) = M, where M is the point in question. Assuming that (u,v)
1336 // is on the involute, and considering the ``standard'' involute, what
1337 // we want is t such that
1338 // u = cos t + t sin t
1339 // v = sin t - t cos t
1340 // I don't think there's any good way to do this, and a bit of googling
1341 // bears that out. I'm not going to try to be mathematically clever.
1342 // Just use Newton's method. So, take the point, M, and "undo" the
1343 // transformation to get M relative to the standard involute -- I mean for
1344 // a unit circle at the origin.
1345 let dM = Math.sqrt((M.x-E.x)**2 + (M.y-E.y)**2);
1346 let aM = dM/rc - a + b - Math.PI;
1347
1348 // Untranslate, unscale and unrotate M.
1349 // BUG: This foolishness is why I should have worked with the standard unit
1350 // involute throughout.
1351 let unitM = new Point2D(M.x - c.x,M.y-c.y);
1352 unitM = new Point2D(unitM.x/rc,unitM.y/rc);
1353 unitM.rotateSelf(-aM);
1354
1355 // Now I want t such that invo2(t).x = unitM.x. I'm using x instead of
1356 // y since y varies very little near the circle and I'm afraid that
1357 // the root finder won't converge well.
1358 // Note that t = 3 is roughly where the derivative changes sign.
1359 // That's why it's a good place for bracketing.
1360 t = Numerical.newton(solveInvo,0.5,0,3,unitM.x,0.00001);
1361
1362 // However, we do NOT want to use a value for t larger than toothT
1363 // since the tooth would make the tooth magically grow to touch M.
1364 if (t > toothT) t = toothT;
1365
1366 p = FPath.parametricToBezier(invo2,0,t,30);
1367 p = p.rotate(aM);
1368 p = p.scale(rc);
1369 p = p.translate(c);
1370
1371 ctx.lineWidth = 1.0;
1372 ctx.stroke(p);
1373
1374 // Now, exactly as above, draw a bit of the involute.
1375 p = FPath.parametricToBezier(invo2,t,toothT,30);
1376 p = p.rotate(aM);
1377 p = p.scale(rc);
1378 p = p.translate(c);
1379
1380 ctx.lineWidth = 0.4;
1381 ctx.stroke(p);
1382
1383 // And...what the heck... some spokes to make the rotation
1384 // more noticable.
1385 p = new FPath();
1386 p.moveTo(c.x,c.y);
1387 let sp = new Point2D(c.x+rc,c.y);
1388 sp = sp.rotateAbout(c,aM);
1389 p.lineTo(sp.x,sp.y);
1390 ctx.lineWidth = 0.4;
1391 ctx.stroke(p);
1392
1393 // let wedgeRange = cVisAngle / 4;
1394 let wedgeRange = Math.PI / 6;
1395 for (let i = 0; i < 10; i++)
1396 {
1397 let a = aM + i*wedgeRange;
1398 //if ((a <= cVisAngle) && (a >= -cVisAngle))
1399 {
1400 p = new FPath();
1401 p.moveTo(c.x,c.y);
1402 let sp = new Point2D(c.x+rc,c.y);
1403 sp = sp.rotateAbout(c,a);
1404 p.lineTo(sp.x,sp.y);
1405 ctx.lineWidth = 0.4;
1406 ctx.stroke(p);
1407 }
1408
1409 a = aM - i*wedgeRange;
1410 //if ((a <= cVisAngle) && (a >= -cVisAngle))
1411 {
1412 p = new FPath();
1413 p.moveTo(c.x,c.y);
1414 let sp = new Point2D(c.x+rc,c.y);
1415 sp = sp.rotateAbout(c,a);
1416 p.lineTo(sp.x,sp.y);
1417 ctx.lineWidth = 0.4;
1418 ctx.stroke(p);
1419 }
1420 }
1421
1422 // Now we have to do almost the same thing, but for the right disk.
1423 // The twist is that the involute is now flipped relative to the
1424 // earlier case because the right disk rotates in the opposite direction.
1425 // That is, swap the sign of the y-coordinate, and the x-coordinate too
1426 // since the disk is on the right.
1427 //
1428 // The tooth height is the same on the right side, but the scale is different,
1429 // so the value of toothT will be different.
1430 toothD = (d.x-c.x-rc - 2) / rd;
1431 toothT = Numerical.newton(solveToothD,0.5,0,3,toothD,0.00001);
1432
1433 // What we want is for the flipped involute to pass through M, although
1434 // it will pass through M at a different value for t. I could work out
1435 // this t by finding it numerically. Or, I could use the fact that --
1436 // because I know how gears work -- the relative rates of rotion are known.
1437 // In fact, because I want the line to change at M, I do need this value
1438 // for t. This is more like what happens physically: the motion of the
1439 // left disk determines M, which pushes the disk on the right to rotate.
1440 //
1441 // Redetermine unitM, as above, but relative to the right disk.
1442 // Do it afresh to avoid any rounding error.
1443 dM = Math.sqrt((M.x-F.x)**2 + (M.y-F.y)**2);
1444 aM = dM/rd - a + b - Math.PI;
1445 unitM = new Point2D(d.x-M.x ,d.y-M.y);
1446 unitM = new Point2D(unitM.x/rd,unitM.y/rd);
1447 unitM.rotateSelf(-aM);
1448
1449 // This is the value for t at which the RH involute passes through M.
1450 t = Numerical.newton(solveInvo,0.5,0,3,unitM.x,0.00001);
1451 if (t > toothT) t = toothT;
1452
1453 // Path from disk to M
1454 p = FPath.parametricToBezier(invo2,0,t,30);
1455 p = p.reflectXY();
1456 p = p.rotate(aM);
1457 p = p.scale(rd);
1458 p = p.translate(d);
1459
1460 ctx.lineWidth = 1.0;
1461 ctx.stroke(p);
1462
1463 // Path from M to the tip of the tooth.
1464 p = FPath.parametricToBezier(invo2,t,toothT,30);
1465 p = p.reflectXY();
1466 p = p.rotate(aM);
1467 p = p.scale(rd);
1468 p = p.translate(d);
1469
1470 ctx.lineWidth = 0.4;
1471 ctx.stroke(p);
1472
1473 // And some spokes for visual appeal, as above.
1474 // The outer arc first.
1475 /*
1476 dVisAngle = 5*Math.PI/8;
1477 p = FPath.arcToBezier(rd,dVisAngle,-dVisAngle);
1478 p = p.rotate(aM);
1479 p = p.translate(d);
1480 ctx.lineWidth = 2.0;
1481 ctx.stroke(p);
1482 */
1483
1484 // And the spokes.
1485 p = new FPath();
1486 p.moveTo(d.x,d.y);
1487 sp = new Point2D(d.x-rd,d.y);
1488 sp = sp.rotateAbout(d,aM);
1489 p.lineTo(sp.x,sp.y);
1490 ctx.lineWidth = 0.4;
1491 ctx.stroke(p);
1492
1493 // In fact, the angle *spanned* by the arc is two times this.
1494 // It's because of the whole LH/RH thing.
1495 for (let i = 0; i < 7; i++)
1496 {
1497 let a = aM + i*wedgeRange;
1498 //if ((a <= dVisAngle) && (a >= -dVisAngle))
1499 {
1500 p = new FPath();
1501 p.moveTo(d.x,d.y);
1502 let sp = new Point2D(d.x-rd,d.y);
1503 sp = sp.rotateAbout(d,a);
1504 //sp.x = d.x - (sp.x - d.x);
1505 p.lineTo(sp.x,sp.y);
1506 ctx.lineWidth = 0.4;
1507 ctx.stroke(p);
1508 }
1509
1510 a = aM - i*wedgeRange;
1511 p = new FPath();
1512 p.moveTo(d.x,d.y);
1513 let sp = new Point2D(d.x-rd,d.y);
1514 sp = sp.rotateAbout(d,a);
1515 p.lineTo(sp.x,sp.y);
1516 ctx.lineWidth = 0.4;
1517 ctx.stroke(p);
1518 }
1519 }
1520
1521 function solveToothD(t) {
1522 let p = invo2(t);
1523 return Math.sqrt(p.x**2 + p.y**2);
1524 }
1525
1526 function solveInvo(t) {
1527 return invo2(t).x;
1528 }
1529
1530 function invo2(t) {
1531
1532 // Involute, assuming circle of radius 1 centered at the origin.
1533 // There is another function called invo(), hence this is invo2().
1534 // BUG: This is the way I should have done this above. Generate a standard
1535 // involute, then scale and rotate as needed.
1536 let c = Math.cos(t);
1537 let s = Math.sin(t);
1538
1539 // Note that y is backwards since LH coordinate system.
1540 return new Point2D( c + t*s , - (s - t*c) );
1541 }
1542 \end{figput}
1543 \caption{Rotation Traces Involutes}
1544 \label{fig-moving-involute}
1545 \end{figure}
1546
1547
1548 Figure (\ref{fig-moving-involute}) shows an enlarged view of the two
1549 base circles of Figure (\ref{fig-constant-pp}), without the pitch
1550 circles. Imagine that a piece of string is tightly
1551 wrapped around one base circle, extends over to the other base circle,
1552 and is wrapped around it too. As the disks rotate, the string unwinds
1553 from one base circle and is taken up by the other base circle. There
1554 is a fixed point on the string that represents the point of
1555 contact between two teeth. This point traces a path that
1556 is an involute relative to either circle. These involutes define the
1557 shape of the mating tooth profiles. The line of action is coincident
1558 with the string, and the two gears have conjugate action.
1559
1560 A fortunate feature of the involute is that the teeth can be truncated at
1561 their perimeter, or their widths may be varied, yet the two gears
1562 still have conjugate action; the teeth come into contact sooner or
1563 later as they rotate, but the point of contact follows the same line
1564 of action. If the center distance changes, then the line of action
1565 also changes, but the tooth form (the involute) remains the same, and
1566 the gears still have conjugate action, though there will be some
1567 backlash and additional friction between the teeth.
1568
1569 What remains is the resolution of many practical issues: the interplay
1570 of gear radius, tooth size, number of teeth and the
1571 like.
1572
1573 The two main methods of gear specification are
1574 metric (ISO) and inch (AGMA), and the two systems use slightly different
1575 fundamental quantities to specify a given gear. These are the basic
1576 parameters used to specify off-the-shelf gear profiles.
1577 \begin{small}
1578 \begin{itemize}[itemsep=-1pt]
1579 \item $\phi$, pressure angle
1580 \item $N$, number of teeth
1581 \item $m$, module (for metric gears)
1582 \item $p_d$, diametral pitch (for inch gears)
1583 \end{itemize}
1584 \end{small}
1585
1586 There are many additional terms and measurements. In fact,
1587 off-the-shelf gears are typically specified in a way that makes
1588 various assumptions. Additional parameters that influence
1589 gear design are
1590 \begin{small}
1591 \begin{itemize}[itemsep=-1pt]
1592 \item $p_c$, circular pitch
1593 \item $d$, pitch diameter
1594 \item $r_p$, pitch radius
1595 \item $r_b$, base radius
1596 \item $a$, addendum
1597 \item $b$, dedendum
1598 %\item $C$, center distance
1599 %\item $r$, pitch radius
1600 \end{itemize}
1601 \end{small}
1602
1603 The \emph{pressure angle}, $\phi$, is the angle between the line of
1604 action and the perpendicular to the line of centers. In Figure
1605 (\ref{fig-moving-involute}), the pressure angle is roughly $35^\circ$.
1606 If two gears are to mesh without backlash, then they must use the same
1607 pressure angle. At one time, $14.5^\circ$ was a commonly used pressure
1608 angle, but $20^\circ$ is the current standard.
1609 A more obviously important choice is the number of teeth, $N$. Since
1610 the number of teeth determines the ratio of any gear train, this is a crucial
1611 choice, but it raises the question of how to fit $N$ teeth on a given
1612 gear.
1613
1614 The tooth-to-tooth distance, as measured along the arc of the pitch
1615 circle, is the \emph{circular pitch}, $p_c$, and the corresponding
1616 diameter is the \emph{pitch diameter}, $d$. Since $N p_c$ is the
1617 circumference of the pitch circle, we have
1618 $$p_c = {\pi d\over N}.$$
1619 This is the inches or mm per tooth, measured along the circumerence. In
1620 practice, AGMA gears are specified by the \emph{diametral pitch},
1621 $$p_d = {N\over d}.$$
1622 This is the teeth per $\pi$ inches, and seems like an odd
1623 choice, but that's how it's done.
1624 Metric gears are specified by their \emph{module}, $m$, which is
1625 stated in millimeters, and is
1626 $$m = {d\over N} = {1\over p_d}.$$
1627 The actual tooth-to-tooth distance is thus $\pi m$.
1628 The values around which the two systems, ISO and AGMA,
1629 are standardized are not compatible. For example, a module of $m=4$
1630 corresponds to a diametral pitch of
1631 $$p_d = {25.4\over 4} = 6.35,$$
1632 which is not a standard AGMA size.
1633
1634 The profile of each gear tooth is an involute, and determining the
1635 involute requires that the base circle be known. See Figure
1636 (\ref{fig-base-from-pitch}), in which the outer circle is the pitch circle and
1637 the inner circle is the base circle. Let $r_p$ be the radius of the
1638 pitch circle, and $r_b$ be the radius of the base circle. Because the
1639 angle determined by where the line of action meets the base circle is
1640 equal to the pressure angle, $\phi$, we have
1641 $$r_b = r_p \cos\phi.$$
1642
1643 \begin{figure}[b!]
1644 \begin{figput}{baseandpitch,175bp}[done,skip]
1645 function baseandpitch(ctx) {
1646
1647 // A static figure, no interaction.
1648 let rc = 70;
1649 let y = 80;
1650
1651 let c = new Point2D(130,y);
1652
1653 // Pitch circle
1654 let p = new FPath();
1655 p.ellipse(c.x,c.y,rc,rc,0,0,2*Math.PI);
1656 ctx.strokeStyle = 'black';
1657 ctx.lineWidth = 0.4;
1658 ctx.stroke(p);
1659
1660 // Radius through pitch point
1661 let pplen = rc + 50;
1662 p = new FPath();
1663 p.moveTo(c.x,c.y);
1664 p.lineTo(c.x+pplen,c.y);
1665 ctx.stroke(p);
1666
1667 // Line of action through P and angle phi. Use tan phi = dx / dy
1668 // to draw a line through P = (c.x+rc,c.y).
1669 let phi = Math.PI / 6;
1670 let lenup = 70;
1671 let lendown = 50;
1672 let tan = Math.tan(phi);
1673 p = new FPath();
1674 p.moveTo(c.x + rc - lenup * tan,c.y + lenup);
1675 p.lineTo(c.x + rc + lendown * tan,c.y - lendown);
1676 ctx.stroke(p);
1677
1678 // Base circle has radius:
1679 let rb = rc * Math.cos(phi);
1680 p = new FPath();
1681 p.ellipse(c.x,c.y,rb,rb,0,0,2*Math.PI);
1682 ctx.strokeStyle = 'black';
1683 ctx.lineWidth = 0.4;
1684 ctx.stroke(p);
1685
1686 // Vertical line through P.
1687 let vlen = 60;
1688 p = new FPath();
1689 p.moveTo(c.x+rc,c.y-vlen);
1690 p.lineTo(c.x+rc,c.y+vlen);
1691 ctx.stroke(p);
1692
1693 // radial line to where line of action meets base circle.
1694 p = new FPath();
1695 p.moveTo(c.x,c.y);
1696 p.lineTo(c.x + rb*Math.cos(phi),c.y+rb*Math.sin(phi));
1697 ctx.stroke(p);
1698
1699 // Little hash marks to indicate angles have same measure.
1700 p = FPath.circArcToBezier(16,0,phi);
1701 p = p.translate(c);
1702 ctx.stroke(p);
1703
1704 p = FPath.circArcToBezier(16,Math.PI/2 - phi,Math.PI/2);
1705 p = p.reflectX();
1706 p = p.translate(new Point2D(c.x+rc,c.y));
1707 ctx.stroke(p);
1708 }
1709
1710 \end{figput}
1711 \caption{Base Circle from Pitch Circle}
1712 \label{fig-base-from-pitch}
1713 \end{figure}
1714
1715
1716 The module or diametral pitch determines the tooth-to-tooth distance,
1717 but it doesn't determine how much of that space is solid tooth and how
1718 much is the space between teeth. The ensure that there is no backlash,
1719 the thickness of each tooth, as measured along the arc of the pitch
1720 circle, should be equal to the space between teeth -- for practical
1721 reasons (lubrication), the gap between teeth is often made one or two
1722 thousandths of an inch wider than this. Again, these distances are
1723 \emph{as measured along the arc of the pitch circle}. In practice, it
1724 is easier to work with the angles subtended by these arcs.
1725
1726 There is one further issue to resolve. See Figure (\ref{fig-teeth-touch}),
1727 which shows a portion of a base circle and slightly larger pitch
1728 circle, with an involute. What's needed is the measure of the small
1729 angle relative to the $x$-axis at which the involute meets the pitch
1730 circle. The involute is parametrized by
1731 $$i(t) = r_b(\cos t + t\sin t,\sin t - t\cos t) = (i_x(t),i_y(t)),$$
1732 and the involute meets the pitch circle when $|i(t)|^2 = r_p^2$. We have
1733 \begin{eqnarray*}
1734 |i(t)|^2 &=& r_b^2\left[(\cos t + t\sin t)^2 + (\sin t - t\cos t)^2\right] \\
1735 &=& r_b^2\left[\cos^2 t + 2t\cos t\sin t + t^2\sin^2t +
1736 \sin^2 t - 2t\cos t\sin t + t^2\cos^2 t\right] \\
1737 &=& r_b^2(1 + t^2),
1738 \end{eqnarray*}
1739 and $|i(t)| = r_p$ implies that
1740 $$t = \sqrt{\left({r_p\over r_b}\right)^2-1} = \sqrt{\left({r_p\over
1741 r_p\cos\phi}\right)^2-1}\ = \tan\phi.$$
1742 The angle made by the line through $i(t)$ with the $x$-axis is
1743 $\alpha$, where\footnote{There
1744 seems to be no standard notation for this angle. In fact, I have
1745 found no mention of this issue in any common reference, even though it's crucial for
1746 determining the profile.}
1747 $$\tan\alpha = i_y(t)/i_x(t).$$
1748
1749 \begin{figure}
1750 \begin{figput}{teethtouch,100bp}[done,skip]
1751 function teethtouch(ctx) {
1752
1753 let c = new Point2D(100,20);
1754 let rb = 80;
1755
1756 // Bit of arc on the right. This is the base circle.
1757 let span = Math.PI/5;
1758 let p = FPath.circArcToBezier(rb,0,span);
1759 //p = p.reflectX();
1760 p = p.translate(c);
1761 ctx.lineWidth = 1.0;
1762 ctx.stroke(p);
1763
1764 // And a slightly larger arc for the pitch circle.
1765 let rp = rb + 22;
1766 p = FPath.circArcToBezier(rp,0,span);
1767 //p = p.reflectX();
1768 p = p.translate(c);
1769 ctx.lineWidth = 0.4;
1770 ctx.stroke(p);
1771
1772 // Draw x-axis/radius.
1773 let width = 150
1774 p = new FPath();
1775 p.moveTo(c.x,c.y);
1776 p.lineTo(c.x+width,c.y);
1777 ctx.lineWidth = 0.4;
1778 ctx.stroke(p);
1779
1780 // Using the earlier invo2() function for the unit involute.
1781 let a = Math.PI/8;
1782 let inv = FPath.parametricToBezier(invo2,0,1.5,30);
1783 p = inv.reflectX();
1784 //p = inv.scale(rb);
1785 p = p.scale(rb);
1786 p = p.translate(c);
1787 ctx.stroke(p);
1788
1789 // And a line out to the point where the top involute meets the pitch circle.
1790 p = new FPath();
1791 p.moveTo(c.x,c.y);
1792 let t = Math.sqrt((rp/rb)**2 - 1);
1793 let q = invo2(t);
1794 q = new Point2D(q.x,-q.y);
1795 q = new Point2D(q.x*rb,q.y*rb);
1796 q = new Point2D(q.x+c.x,q.y+c.y);
1797 p.lineTo(q.x,q.y);
1798 ctx.lineWidth = 0.4;
1799 ctx.stroke(p);
1800 }
1801 \end{figput}
1802 \caption{Angle Subtended by Involutes.}
1803 \label{fig-teeth-touch}
1804 \end{figure}
1805
1806 We now have enough information to begin laying out gear
1807 profiles. Suppose that $\phi$, $N$ and $m$ (or $p_d$) are given. There
1808 will be $N$ involutes runing one way, and $N$ running the other
1809 way. Relative to the base circle, the tooth-to-tooth distance subtends
1810 an angle measuring $2\pi/N$. Half of this is solid tooth, and half is the
1811 gap between teeth, with an adjustment for $\alpha$. So each solid
1812 tooth subtends the angle $\pi/N + 2\alpha$, and each gap
1813 subtends the angle $\pi/N - 2\alpha$. Figure~(\ref{fig-gear-example})
1814 shows the result for $\phi = 20^\circ$, $N=15$ and $m =4$.
1815
1816 \begin{figure}
1817 \begin{figput}{gearexample,120bp}[done,skip]
1818 function gearexample(ctx) {
1819
1820 // Note that I may have written this for a LH coordinate system, but
1821 // it doesn't matter since it's radially symmetric.
1822
1823 // Pressure angle, number of teeth and module.
1824 let phi = 20 * Math.PI / 180;
1825 let N = 15;
1826 let m = 5;
1827
1828 let c = new Point2D(175,60);
1829 let pitchDiam = N * m;
1830
1831 // Pitch radius and base radius.
1832 let rp = pitchDiam / 2;
1833 let rb = rp * Math.cos(phi);
1834
1835 ctx.lineWidth = 0.4;
1836
1837 // Point along parameterization where involute meets pitch circle.
1838 let t = Math.tan(phi);
1839
1840 // Adjustment to width of the base of the teeth due to the fact that
1841 // the teeth are of varying width. Note that the radius of the base circle
1842 // doesn't matter.
1843 let ipt = invo2(t);
1844 let alpha = -Math.atan2(ipt.y,ipt.x);
1845
1846 ctx.lineWidth = 0.4;
1847
1848 // Each tooth, at the base, takes 2pi/2N + 2 alpha. The space between
1849 // teeth is 2pi/2N - 2 alpha
1850 //
1851 // We want the x-axis to split a gap between teeth, so the first tooth
1852 // starts at (pi/N - 2 alpha) / 2 = pi/2N - alpha.
1853 //
1854 // Using earlier function for the unit involute.
1855 // Note that the angles are all backwards (reversed sign) due to LH coords.
1856
1857 let basicInv = FPath.parametricToBezier(invo2,0,1,30);
1858 let basicArc = FPath.circArcToBezier(rb,0,Math.PI/N - 2*alpha);
1859 basicArc = basicArc.reflectX();
1860
1861 let angle = -Math.PI / (2*N) + alpha;
1862 ctx.strokeStyle='black';
1863
1864 for (let i = 0; i < N; i++)
1865 {
1866 // One side of tooth.
1867 let inv = basicInv.rotate(angle);
1868 inv = inv.scale(rb);
1869 inv = inv.translate(c);
1870 ctx.stroke(inv);
1871
1872 // Other side of tooth.
1873 angle -= Math.PI / N + 2 * alpha;
1874 inv = basicInv.reflectX();
1875 inv = inv.rotate(angle);
1876 inv = inv.scale(rb);
1877 inv = inv.translate(c);
1878 ctx.stroke(inv);
1879
1880 // Gap between teeth.
1881 let gap = basicArc.rotate(angle);
1882 gap = gap.translate(c);
1883 //ctx.strokeStyle='blue';
1884 ctx.stroke(gap);
1885
1886 angle -= Math.PI / N - 2*alpha;
1887 }
1888 }
1889
1890 \end{figput}
1891 \caption{Basic Gear Form.}
1892 \label{fig-gear-example}
1893 \end{figure}
1894
1895 There is a glaring problem with Figure (\ref{fig-gear-example}): the
1896 involutes continue beyond the point where the two sides of each tooth
1897 meet. If the aim is to program a milling machine to cut these profiles,
1898 then that's not a big deal -- the machine will be cutting a bit of
1899 air beyond the end of each tooth -- but it would be nice to know
1900 exactly where the two sides meet. Suppose that a tooth is symmetric
1901 about the $x$-axis so that the two sides meet at $y=0$. Let $R_\theta$
1902 be the rotation matrix through angle $\theta$. Then the involute below
1903 the $x$-axis is parameterized by $R_{-\theta}i(t)$, where $\theta
1904 = \alpha + \pi/2N$. In particular, we want to find $t$ such that the
1905 $y$-coordinate of $R_{-\theta}i(t)$ is equal to zero. We have
1906 \begin{eqnarray*}
1907 R_{-\theta}\ i(t) &=& \pmatrix{\cos\theta&\sin\theta\cr-\sin\theta&\cos\theta}
1908 \pmatrix{r_b(\cos t + t\sin t)\cr r_b(\sin t - t\cos t)},
1909 \end{eqnarray*}
1910 and we require $t$ such that
1911 $$-r_b\sin\theta(\cos t + t\sin t) + r_b\cos\theta(\sin t - t\cos t) = 0$$
1912 or
1913 $${\sin t - t\cos t\over \cos t + t\sin t} = \tan\theta.$$
1914 Unfortunately, finding such $t$ requires the use of numerical methods
1915 of approximation. Making use of something like Newton-Raphson to
1916 determine $t$, we obtain Figure (\ref{fig-gear-ex-better}).
1917
1918 \begin{figure}
1919 \begin{figput}{bettergear,120bp}[done,skip]
1920 function bettergear(ctx) {
1921
1922 // As above, but the teeth meet properly instead of having ``hair.''
1923
1924 // Pressure angle, number of teeth and module.
1925 let phi = 20 * Math.PI / 180;
1926 let N = 15;
1927 let m = 5;
1928
1929 let c = new Point2D(175,60);
1930 let pitchDiam = N * m;
1931
1932 // Pitch radius and base radius.
1933 let rp = pitchDiam / 2;
1934 let rb = rp * Math.cos(phi);
1935
1936 ctx.lineWidth = 0.4;
1937
1938 // Point along parameterization where involute meets pitch circle.
1939 let t = Math.tan(phi);
1940
1941 // Adjustment to width of the base of the teeth due to the fact that
1942 // the teeth are of varying width. Note that the radius of the base circle
1943 // doesn't matter.
1944 let ipt = invo2(t);
1945 let alpha = -Math.atan2(ipt.y,ipt.x);
1946
1947 ctx.lineWidth = 0.4;
1948
1949 // Each tooth, at the base, takes 2pi/2N + 2 alpha. The space between
1950 // teeth is 2pi/2N - 2 alpha
1951 //
1952 // We want the x-axis to split a gap between teeth, so the first tooth
1953 // starts at (pi/N - 2 alpha) / 2 = pi/2N - alpha.
1954 //
1955 // Using earlier function for the unit involute.
1956 // Note that the angles are all backwards (reversed sign) due to LH coords.
1957 //
1958 // We also solve for t so that the teeth meet as they should.
1959 let targetV = Math.tan(Math.PI/(2*N) + alpha);
1960 let toothT = Numerical.newton(toothMeet,0.3,0,2,targetV,0.00001);
1961
1962 let basicInv = FPath.parametricToBezier(invo2,0,toothT,30);
1963 let basicArc = FPath.circArcToBezier(rb,0,Math.PI/N - 2*alpha);
1964 basicArc = basicArc.reflectX();
1965
1966 let angle = -Math.PI / (2*N) + alpha;
1967 ctx.strokeStyle='black';
1968
1969 for (let i = 0; i < N; i++)
1970 {
1971 // One side of tooth.
1972 let inv = basicInv.rotate(angle);
1973 inv = inv.scale(rb);
1974 inv = inv.translate(c);
1975 ctx.stroke(inv);
1976
1977 // Other side of tooth.
1978 angle -= Math.PI / N + 2 * alpha;
1979 inv = basicInv.reflectX();
1980 inv = inv.rotate(angle);
1981 inv = inv.scale(rb);
1982 inv = inv.translate(c);
1983 ctx.stroke(inv);
1984
1985 // Gap between teeth.
1986 let gap = basicArc.rotate(angle);
1987 gap = gap.translate(c);
1988 //ctx.strokeStyle='blue';
1989 ctx.stroke(gap);
1990
1991 angle -= Math.PI / N - 2*alpha;
1992 }
1993 }
1994
1995 function toothMeet(t) {
1996
1997 // Used to solve for the t at which the two sides of a tooth meet.
1998 let s = Math.sin(t);
1999 let c = Math.cos(t);
2000 return (s - t*c) / (c + t * s);
2001 }
2002
2003 \end{figput}
2004 \caption{Corrected Gear Form.}
2005 \label{fig-gear-ex-better}
2006 \end{figure}
2007
2008 Figure (\ref{fig-gear-ex-better}) still doesn't look quite
2009 right. Gears don't typically have such pointy-ended teeth, and the gaps
2010 between the teeth don't seem deep enough in Figure
2011 (\ref{fig-gear-ex-better}). There are two more parameters to adjust
2012 for this: the \emph{addendum}, $a$, and \emph{dedendum}, $b$. The
2013 addendum is the distance above the pitch circle to which the teeth
2014 extend; when a tooth reaches a radius of $r_p + a$, it is truncated
2015 and given a flat top (the so-called \emph{top land}). The dedendum is
2016 the depth below the pitch circle to which the gap between teeth is
2017 cut; so the gaps are cut to a radius of $r_p -b$ (forming the
2018 so-called \emph{bottom land}). While the parameters $a$ and $b$ could
2019 take any value, they have been standardized to
2020 $$a = m\qquad{\rm and}\qquad b = 1.25\ m.$$
2021 Under the AGMA system (inches), these are
2022 $$a = 1/p_d\qquad{\rm and}\qquad b = 1.25/p_d.$$
2023 Teeth have been standardized this way because the tips of pointy-ended
2024 teeth are prone to burring, while cutting the gaps more deeply allows
2025 for fuller engagement of the teeth. Figure (\ref{fig-gear-with-add-ded})
2026 shows the same gear as in Figure (\ref{fig-gear-ex-better}), but with
2027 the addendum and dedendum circles.
2028
2029 \begin{figure}[b!]
2030 \begin{figput}{gearaddded,120bp}[done,skip]
2031 function gearaddded(ctx) {
2032
2033 // As above, but with (or without when interactive) the various circles.
2034
2035 // A button for show/hide the extra circles.
2036 let wbut = ButtonWidget.register(ctx,-80,10,'Show/Hide','but');
2037
2038 // Pressure angle, number of teeth and module.
2039 let phi = 20 * Math.PI / 180;
2040 let N = 15;
2041 let m = 5;
2042
2043 let c = new Point2D(175,60);
2044 let pitchDiam = N * m;
2045
2046 // Pitch radius and base radius.
2047 let rp = pitchDiam / 2;
2048 let rb = rp * Math.cos(phi);
2049
2050 ctx.lineWidth = 0.4;
2051
2052 if (wbut.clickState === true)
2053 {
2054 // Pitch circle.
2055 p = new FPath();
2056 p.ellipse(c.x,c.y,rp,rp,0,0,2*Math.PI);
2057 ctx.stroke(p);
2058
2059 // Addendum
2060 radd = rp + m;
2061 p = new FPath();
2062 p.ellipse(c.x,c.y,radd,radd,0,0,2*Math.PI);
2063 ctx.stroke(p);
2064
2065 // Dedendum
2066 rded = rp - 1.25* m;
2067 p = new FPath();
2068 p.ellipse(c.x,c.y,rded,rded,0,0,2*Math.PI);
2069 ctx.stroke(p);
2070 }
2071
2072
2073 // Point along parameterization where involute meets pitch circle.
2074 let t = Math.tan(phi);
2075
2076 // Adjustment to width of the base of the teeth due to the fact that
2077 // the teeth are of varying width. Note that the radius of the base circle
2078 // doesn't matter.
2079 let ipt = invo2(t);
2080 let alpha = -Math.atan2(ipt.y,ipt.x);
2081
2082 ctx.lineWidth = 0.4;
2083
2084 // Each tooth, at the base, takes 2pi/2N + 2 alpha. The space between
2085 // teeth is 2pi/2N - 2 alpha
2086 //
2087 // We want the x-axis to split a gap between teeth, so the first tooth
2088 // starts at (pi/N - 2 alpha) / 2 = pi/2N - alpha.
2089 //
2090 // Using earlier function for the unit involute.
2091 // Note that the angles are all backwards (reversed sign) due to LH coords.
2092 //
2093 // We also solve for t so that the teeth meet as they should.
2094 let targetV = Math.tan(Math.PI/(2*N) + alpha);
2095 let toothT = Numerical.newton(toothMeet,0.3,0,2,targetV,0.00001);
2096
2097 let basicInv = FPath.parametricToBezier(invo2,0,toothT,30);
2098 let basicArc = FPath.circArcToBezier(rb,0,Math.PI/N - 2*alpha);
2099 basicArc = basicArc.reflectX();
2100
2101 let angle = -Math.PI / (2*N) + alpha;
2102 ctx.strokeStyle='black';
2103
2104 for (let i = 0; i < N; i++)
2105 {
2106 // One side of tooth.
2107 let inv = basicInv.rotate(angle);
2108 inv = inv.scale(rb);
2109 inv = inv.translate(c);
2110 ctx.stroke(inv);
2111
2112 // Other side of tooth.
2113 angle -= Math.PI / N + 2 * alpha;
2114 inv = basicInv.reflectX();
2115 inv = inv.rotate(angle);
2116 inv = inv.scale(rb);
2117 inv = inv.translate(c);
2118 ctx.stroke(inv);
2119
2120 // Gap between teeth.
2121 let gap = basicArc.rotate(angle);
2122 gap = gap.translate(c);
2123 //ctx.strokeStyle='blue';
2124 ctx.stroke(gap);
2125
2126 angle -= Math.PI / N - 2*alpha;
2127 }
2128 }
2129
2130 \end{figput}
2131 \caption{Gear with Addedenum and Dedendum Circles.}
2132 \label{fig-gear-with-add-ded}
2133 \end{figure}
2134
2135 It is now possible to specify the standard tooth profile for a gear
2136 with arbitrary parameters, as in Figure ({\ref{fig-final-gear}). The
2137 value for $t$ to which the parameterization of the involute extends
2138 must be adjusted. Instead of extending out to the value of $t_0$ for
2139 which
2140 $${\sin t_0 - t_0\cos t_0\over \cos t_0 + t_0\sin t_0} = \tan\theta,$$
2141 $t$ must be chosen so that $|i(t)| = r_p + a$. This is simpler to
2142 determine since $\theta$ no longer plays a role. As in an earlier
2143 calculation, we must have
2144 \begin{eqnarray*}
2145 (r_p+a)^2 &=& |i(t)|^2 \\
2146 &=& r_b^2(1+t^2)
2147 \end{eqnarray*}
2148 or
2149 $$t\ =\ \sqrt{\left({r_p+a\over r_b}\right)^2 - 1}\ =\
2150 \sqrt{\left({r_p+a\over r_p\cos\phi}\right)^2 - 1}.$$
2151 Of course, $a$ can't be chosen to produce a value for $t$ larger than $t_0$.
2152
2153 When drawing gears with a given addendum, it can be useful to know the
2154 angle subtended by the top land. As noted above, the angle subtended
2155 relative to the base circle by each tooth is $\pi/N + 2\alpha$. Let
2156 $t_d$ be the value for $t$ at which the top land begins. Each
2157 side of the tooth, from the base circle to the top land subtends the
2158 angle $\beta$, where $\tan\beta = i_y(t_d)/i_x(t_d)$. The top land
2159 thus subtends the angle $\pi/N + 2\alpha - 2\beta$.
2160
2161 \begin{figure}
2162 \begin{figput}{gearfinal,200bp}[done,skip]
2163 function gearfinal(ctx) {
2164
2165 // As above, but allow the user to tweak the settings. Further, we use the
2166 // standard values for addendum and dedendum. This changes the way the
2167 // involutes and gaps are drawn.
2168 //
2169 // BUG: There's some problem here of a mathematical or graphical nature.
2170 // If I lift the restrictions on the inputs, things go haywire at
2171 // the extremes.
2172
2173 // Default pressure angle, number of teeth and module.
2174 let phi = 20 * Math.PI / 180;
2175 let N = 15;
2176 let m = 5;
2177
2178 // Let the user change these.
2179 let leftInput = -50;
2180 let toothInput = NumberInputWidget.register(ctx,leftInput,20,15,"tooth");
2181 N = parseInt(toothInput.getValue());
2182 if (N < 4)
2183 {
2184 toothInput.theWidget.value = 4;
2185 N = 4;
2186 }
2187 if (N > 30)
2188 {
2189 toothInput.theWidget.value = 30;
2190 N = 30;
2191 }
2192
2193 let paInput = NumberInputWidget.register(ctx,leftInput,35,20,"pa");
2194 phi = parseFloat(paInput.getValue());
2195 if (phi > 25)
2196 {
2197 paInput.theWidget.value = 25;
2198 phi = 25;
2199 }
2200 if (phi < 5)
2201 {
2202 paInput.theWidget.value = 5;
2203 phi = 5;
2204 }
2205 phi = phi * Math.PI / 180;
2206
2207 let moduleInput = NumberInputWidget.register(ctx,leftInput,50,5,"mod");
2208 m = parseFloat(moduleInput.getValue());
2209 if (m > 6)
2210 {
2211 moduleInput.theWidget.value = 6;
2212 m = 6;
2213 }
2214 if (m < 1)
2215 {
2216 moduleInput.theWidget.value = 1;
2217 m = 1;
2218 }
2219
2220 let leftText = -120;
2221 let upText = 30;
2222 ctx.font = '10px san-serif';
2223 ctx.fillStyle = 'black';
2224 drawTextBrowserOnly(ctx,'Tooth Count',leftText,35-upText);
2225 drawTextBrowserOnly(ctx,'Pressure Angle',leftText,50-upText);
2226 drawTextBrowserOnly(ctx,'Module',leftText,65-upText);
2227
2228 // Addendum and dedendum.
2229 // BUG: I could let the user adjust these too.
2230 let a = m;
2231 let b = 1.25 * m;
2232
2233 let c = new Point2D(150,100);
2234 let pitchDiam = N * m;
2235
2236 // Pitch radius and base radius.
2237 let rp = pitchDiam / 2;
2238 let rb = rp * Math.cos(phi);
2239
2240 ctx.lineWidth = 0.4;
2241
2242 // Center of gear.
2243 let p = new FPath();
2244 p.ellipse(c.x,c.y,1.5,1.5,0,0,2*Math.PI);
2245 ctx.fill(p);
2246
2247 // Point along parameterization where involute meets pitch circle.
2248 let t = Math.tan(phi);
2249
2250 // Adjustment to width of the base of the teeth due to the fact that
2251 // the teeth are of varying width. Note that the radius of the base circle
2252 // doesn't matter.
2253 let ipt = invo2(t);
2254 let alpha = -Math.atan2(ipt.y,ipt.x);
2255
2256 // Determine the maximum value for t. This is the point at which the
2257 // sides of a tooth meet. It determines the maximum possible value
2258 // for the addendum.
2259 let targetV = Math.tan(Math.PI/(2*N) + alpha);
2260 let maxT = Numerical.newton(toothMeet,0.3,0,2,targetV,0.00001);
2261
2262 // Now the value of t determined by the addendum.
2263 let T = Math.sqrt(((rp + a)/rb)**2 - 1);
2264 if (T > maxT)
2265 T = maxT;
2266
2267 // These are the parts of the gear profile. There's a tricky thing here in
2268 // that the arc subtended by the top land must be determined.
2269 // The arc subtended by half a tooth (out to maxT) is known to be
2270 // pi/(2N) + alpha, but the involute now spans a smaller angle and the top
2271 // land makes up the difference. This smaller angle is determined by
2272 // invo(T), and the angle is beta such that
2273 // tan(beta) = y(T)/x(T).
2274 let basicInv = FPath.parametricToBezier(invo2,0,T,30);
2275 let basicBot = FPath.circArcToBezier(rp-b,0,Math.PI/N - 2*alpha);
2276
2277 ipt = invo2(T);
2278 let beta = -Math.atan2(ipt.y,ipt.x);
2279 let basicTop = FPath.circArcToBezier(rp+a,0,Math.PI/N + 2*alpha - 2*beta);
2280
2281 // Due to LH coordinates.
2282 basicTop = basicTop.reflectX();
2283 basicBot = basicBot.reflectX();
2284
2285 // Add a radial line on each side of basicInv so that the tooth reaches
2286 // the dedendum circle.
2287 basicInv = basicInv.scale(rb);
2288 basicInv.frontLineTo(rp-b,0);
2289
2290 let angle = -Math.PI / (2*N) + alpha;
2291 ctx.strokeStyle='black';
2292
2293 for (let i = 0; i < N; i++)
2294 {
2295 // One side of tooth.
2296 let inv = basicInv.rotate(angle);
2297 inv = inv.translate(c);
2298 ctx.stroke(inv);
2299
2300 // Arc of top land.
2301 let top = basicTop.rotate(angle - beta);
2302 top = top.translate(c);
2303 ctx.stroke(top);
2304
2305 // Other side of tooth.
2306 angle -= Math.PI / N + 2 * alpha;
2307 inv = basicInv.reflectX();
2308 inv = inv.rotate(angle);
2309 inv = inv.translate(c);
2310 ctx.stroke(inv);
2311
2312 // Gap between teeth.
2313 let gap = basicBot.rotate(angle);
2314 gap = gap.translate(c);
2315 ctx.stroke(gap);
2316
2317 angle -= Math.PI / N - 2*alpha;
2318 }
2319 }
2320 \end{figput}
2321 \caption{Standard Gear Profile.}
2322 \label{fig-final-gear}
2323 \end{figure}
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340 \end{document}
2341
2342