I want an opening shot looking down on a spiral galaxy, not unlike our own. I figured a spiral was a good starting block for this. With a spiral EP curve, I could attach paint effects and guide particles in a typical, galactic, spirally fashion.
A friend has pointed out to me several times that when modelling in 3d, it’s how it looks that is important, not the degree of accuracy in the behind-the-scenes modelling. Knowing this, I should just draw a spiral freehand. However, I found it much more satisfying (and time consuming) working out to automatically create mathematically precise spirals using MEL.
Initially, I searched the web for a spiral script – surely someone else would have had need to create neat, precise spirals in Maya before? I found a few scripts, but none of them really worked how I wanted them to work. Further, I thought it would be interesting to understand the maths underlying spiral creation. Firing up Google, and with my handy copy of Complete Maya Programming to hand, I set to work.
Things I needed to know
An Archimedes spiral is a spiral whose consecutive turns are all a constant distance from one another.
Maya uses the Cartesian coordinate system; A given point is defined by 3 dimensions: x, y, z. Together, these three values represent a points unique position in 3d space. For a 2d shape, such as a flat spiral, we can safely ignore the z value, which would otherwise give our spiral depth.
Polar coordinates are an alternate coordinate system, where a point is represented in 2d space by the equation p = (r, Θ). R is the distance of the point from the origin, Θ represents the angle (in radians) around the axis perpendicular to the 2d plane. (3d polar coordinates use a 3rd value, Φ, which specifies a rotation around the x\z axis).
Why are we talking about polar geometry? Well, an Archimedes spiral can be described using the polar equation r=Θ. Actually, the exact equation is r(Θ) = a + bΘ, but for our purposes we will assume a = 0 and b=1, which helps simplify the equation.
a is a fixed value, and specifies the initial turn of the spiral. It is between 0 and 2π radians.
b represents the distance between consecutive turns
r represents the distance of the point from the origin.
Θ represents the angle around the origin, in radians.
How can we convert this equation into a Cartesian function?
We can ignore a and assume a value of 0, negating its presence in the equation. This gives us r(Θ) = bΘ
b is a fixed value, we can assume this to be 1, and modify as necessary. This reduce the equation further to r(Θ) = Θ (The polar equivalent of y = x!)
Θ is calculated in radians within the polar equation. To plot a spiral, we need to calculate a set number of points per revolution (4 minimum). The more points we calculate, the more accurate the spiral, although the more intensive for Maya to work with. Working in degrees gives us nice whole nunbers to work in – a full turn of spiral covers 360 degrees, at a coordinate every 10 degrees, that produces 36 points per turn. I decided on a point every 20 degrees (18 points per turn). It is easy then run through a loop, incrementing the counter by 20, and then converting this to radians for our formula.
So a point is calculated in radians with the formula p = (r, Θ) – as Θ increases, so does r (as r=Θ). As we calculate the varying degrees, by stepping through our loop, we can plot the points in a polar view, and will need to convert them to Cartesian coordinates in order to plot them within Maya.
Polar coordinates can be converted to Cartesian coordinates using p = (r cos(Θ), r sin(Θ), 0) (Note that the z value of 0 merely indicates that we are creating a 2d spiral.)
This gives us x = r cos(Θ), y = r sin(Θ) which can be easily plotted to a spiral using MEL.

Sample archimedes spiral, drawn in Maya
Archimedes spiral MEL script for Maya
Download mySpiral.mel (version 1.0) (Right click to download)
This file is commented so you can easily experiment with different values – try them and see what you get. I plan on giving this script a front end though, so can try different values much more easily.