Page 200 - Hacking Roomba
P. 200
Chapter 9 — Creating Art with Roomba 181
Hypotrochoid Curves
The equation that describes the curves a Spirograph makes is not that different from the
one for the circle. However, since it is a moving circle r within a fixed circle R, the equation
becomes a little more complex:
x = (R-r) cos(t) + d cos( ((R-r)/r)t )
y = (R-r) sin(t) - d sin( ((R-r)/r)t )
The types of curves produced by the above equation are called hypotrochoid curves. The
Spirograph also makes another type, called epitrochoid curves. These differ in that the moving
circle goes on the outside of the fixed circle instead of the inside. The epitrochoid curves are
usually less interesting, so the hypotrochoids will be focused on.
Lissajous Curves
Another set of curves somewhat related to these curves are Lissajous curves. The general equa-
tion of them is:
x = A sin( at + d )
y = B sin( bt )
You’ve probably seen Lissajous curves. They are the moving curve shapes on computer displays
in the background of old sci-fi movies.
SpiroExplorer
It can be difficult to get a feel for how the preceding equations result in different curves. All
the equations take a set a parameters and spit out an x,y pair. Usually, the parameter t is varied
while the other parameters like R, r, and d are kept constant.
Listing 9-1 shows a basic version of SpiroExplorer, a Processing sketch to experiment with dif-
ferent parametric curves. Figure 9-13 shows SpiroExplorer in action. The full SpiroExplorer
sketch enables you to modify R, r, and d in real-time using keys on the keyboard. The update
_xy() function is the heart of the sketch. It starts by saving the old values of x,y to xo,yo and
then computes new values of x,y using whichever parametric equation you like. In Listing 9-1
the Java version of the hypotrochoid equation is being used. The update_xy() function also
increments the angle t (which you can also think of as time here) by some incremental value
called dt. dt is the step size you use to walk through the equation. When setting dt to a larger
value, SpiroExplorer appears to move more quickly through the equation, whereas a smaller dt
makes for a slower but smoother curve. The line() command draws each little bit of the line
drawing from xo.yo to x,y. You can modify update_xy() to use any function that sets x and y,
like the Lissajous and circle equations (shown but commented out), or any other equation you
can think of.