Rotary Harmonographs

Reading about rotary harmonographs in the Quadrivium, it was of course necessary for me to write scheme code to simulate one. This simulates a pen moving circularly in one direction, on a piece of paper moving circularly in the other direction. This, in turn, provides an interesting way to visualize harmonic ratios.

Formulas on the Internet focus on trigonometric functions for x and y axes. But it seems more appealing to deal with this using rotations of complex numbers. This is the basic math:

#lang racket
(require plot)
(define ei (exp 0+1i))
(define (rot ang/tunit t phase)
(expt ei (+ phase (* ang/tunit t))))
(define tau (* 2 pi))
(define (compnums ti samples f1 f2)
(let ([ang0 (/ tau f1)]
[ang1 (/ tau f2)])
(map (lambda (n)
(let ([t (* n ti)])
(+
(rot ang0 t 0)
(rot ang1 t 0))))
(range 0 (- samples 1))))

And we need some interface code to generate the plot:

(define (complex2vec c) (vector (real-part c) (imag-part c)))
(define (rotaryplot ti samples f1 f2)
(plot
(lines
(map
complex2vec
(compnums ti samples f1 f2)))))

Here, we have the basic circle generated by matching frequencies:

Next we do the octave (2:1):

We get quite a different plot if we have the pen turning in the opposite direction of the paper:

And the 4:3 ratio (known as a “Fourth” in music):

This would be more artistic if we introduced some dampening (friction) like in a physical harmonograph, and a small amount of discord. But, it is getting late, and I have to face that day job tomorrow, so that will have to wait for some other evening.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s