Page 199 - Hacking Roomba
P. 199
180 Part II — Fun Things to Do
Figure 9-12 shows such a circle, with the point x,y being angle t above the horizontal. Using
standard trigonometric functions, you can solve for x and y to get:
x = r cos(t)
y = r sin(t)
The angle t is the same as the angle θ (theta) you used in Chapter 5 when you were calculating
a radius for the DRIVE command. In parametric equations like the ones here, theta is usually
replaced by just t. In Figure 9-12 the angle t represents which direction to go from the center
of the circle to some point on its edge.
r
y
t
x
FIGURE 9-12: Circle parameterized
This is a parametric equation for a circle, and you could write a little Processing program to
draw circles with it. If you think of t as time instead of an angle, then as time increases, the
point x,y revolves around and around in an anti-clockwise motion, like a clock’s second hand
going backward. (Math isn’t backward, our convention of clockwise is.) In Processing, t could
be based off of the number of frames displayed, and you could make a little clock or a moving
earth-moon diagram.
Figure 9-12 and the math above are derived from the unit circle, so called because the radius
has been set to one. Analyzing unit circles is the basis for much of trigonometry. To learn
more about the unit circle and general trigonometry, visit The Math Page website (http://
mathpage.com/), particularly the page on unit circles at http://themathpage.com/aTrig/
unit-circle.htm. Also, Wikipedia has a page with extremely useful unit circle diagrams at
http://en.wikipedia.org/wiki/Unit_circle.