Driving a cyclic motion
A pendulum is a weight suspended from a fixed point, free to swing back and forth. It has many real-life applications in time, gravity, and geographic measurements, while in 3D, an oscillating motion is used for displaying clock mechanisms, hanging props, and other cyclic motions. The trigonometric function sine is commonly used to simulate this kind of motion.
The sin
function from the math
module is the Python syntax for sine. We encountered sine in Chapter 7, where we used its inverse, arcsine, to orient objects using Python. Sine is a periodic wave function – it repeats itself at fixed intervals:
Figure 9.6: The sine function
Playing the animation will make the cube jitter very fast. To slow it down, we can click Driven Property and give the formula a slower pace.
For instance, we can change it to sin(frame/10)
and it will slow down tenfold. Now, the cube rocks back and forth gently. We can do even better and set...