Eric Weeks - personal pages - misc

# Spiral Triangles

A simple way to make interesting spirals. See the bottom of the page for links to other simple algorithms like this one.

weeks@physics.emory.edu NOTE: I also wrote a page about mathematical spirals (Archimedes' Spiral, etc). I learned this idea from George Francis when I took his Math 198 class (which, from his web page, it looks like he is still teaching; it's a good class, I recommend it).

The basic idea is to start with a triangle, interpolate to find a point a fraction of the way down a side, draw a line to this point, and use that point as the new corner for the triangle. This will make a picture that looks like this: Here's the simple awk script that made that picture:

BEGIN { ee = 0.08; x1=0; y1=0; x2=10; y2=0; x3=5; y3=5*sqrt(3); print x1,y1,x2,y2,x3,y3,x1,y1; for (t=0;t<100;t++) { x4 = ee*x2 + (1-ee)*x3; y4 = ee*y2 + (1-ee)*y3; print x4,y4; x3=x2; y3=y2; x2=x1; y2=y1; x1=x4; y1=y4; } } ' | psdraw -l 0.1 -X - - - 10 > spi0.ps

The variable "ee" is the scale factor used to determine how tight the spiral is.

Since psdraw can handle colors, I could make the following picture: That was made with this script (using "gawk" to handle trig functions):

gawk ' BEGIN { ee = 0.02; x1=0; y1=0; x2=10; y2=0; x3=5; y3=5*sqrt(3); print x1,y1,0,0,0; # black outline print x2,y2,0,0,0; print x3,y3,0,0,0; print x1,y1,0,0,0; for (t=0;t<100;t++) { x4 = ee*x2 + (1-ee)*x3; y4 = ee*y2 + (1-ee)*y3; print x4,y4,sin(t/4),0,cos(t/4); x3=x2; y3=y2; x2=x1; y2=y1; x1=x4; y1=y4 } } ' | psdraw -l 0.1 -X - - - 10 -C > spi3.ps

Of course, if you write a computer program you can do some more powerful things (such as the picture at the top of the page). I just put in the awk scripts to emphasize how simple this algorithm is. I wrote a C program that fills the triangles, and makes six in a pattern. This program made the picture at the top, and made the following pictures:   Click here to get a copy of this C program. To compile, use "cc -o spiral spiral.c -lm". NOTE: I just added a page about mathematical spirals (Archimedes' Spiral, etc).

Hey, someone linked to this web page! There is a French web page with lots of math resources that put in a link to this page. • Odds and Ends: These are various tiny ideas that are simple to do which make interesting pictures, or are otherwise interesting (to me). Click one of the pictures below to see others.      Simple trigonometric plot | Double-trigonometric contour plot | Lissajous figures | Simple diffusion limited aggregation | Spiral triangles | Polar flowers