Generating Harmonic Motion
While trying to program the curves produced by Spirograph toys in Grasshopper, I took a slightly different path. The topic eventually led to a broader heading: harmonic motion, and from there, to the Fourier Series we looked at previously. This simple Python code models Fourier Synthesis, driven by circles of different radii in a very straightforward way. The Python component sets up a loop that calculates the effect of each circle to the x and y values, individually. In this loop, the angle of each circle at a given time t (provided as input) is calculated. You can enter the radii of however many circles you want sequentially into the list in the r input. The f input gives the rotation frequency of the circles, so this value is multiplied by t to find the angle at a specific moment. The p list represents the phase, allowing us to change the initial angle values of the circles. Ultimately, after calculating an angle value for each circle, the cosine and sine of this value are added to our x and y coordinates. This process is repeated for all circles, until we find the total x and total y values. Let’s check a few different results:



import math
from Rhino.Geometry import Point3d, Polyline
pts = []
t = 0.0
while t < T:
x = 0.0
y = 0.0
for i in range(len(r)):
angle = f[i] * t + p[i]
x += r[i] * math.cos(angle)
y += r[i] * math.sin(angle)
pts.append(Point3d(x, y, 0))
t += step
path = Polyline(pts)

If you examine it a bit, some of the results resemble the path followed by a weight hanging from the ceiling as it swings like a pendulum. This has been the simplest and most fundamental method I’ve achieved in this field so far. By solving the loop inside the Python component, there was no need to use an add-on. My technical knowledge on this subject is very limited. We can continue reading about this topic under headings like Additive Harmonic Synthesis or Fourier Synthesis. However, we have revisited the Fourier Series we looked at earlier in a much simpler, but less visual way. Be careful about the step input: if you make it too small, your computer can freeze.






