4/01/2011

The Logarithmic Spiral

The nautilus shell, poster child of the Logarithmic Spiral, is also an excuse to put a pretty picture in this ugly shell of a blog. Here's a snippet for you to use this beautiful curve.

The function of a logarithmic spiral in parametric form is:
where a and b are constants that affect the curvature of the spiral. Translating that formula to actionscript gives us: function logSpiral(r:Number, a:Number,b:Number, dir:int, cx:Number=0,cy:Number=0):Point{ if(dir<0){dir=-1;} // just to make sure dir is -1 or 1 else{dir=1;} var pt:Point=new Point(); pt.x=dir*a*Math.pow(Math.E,b*r)*Math.cos(r)+cx; pt.y=a*Math.pow(Math.E,b*r)*Math.sin(r)+cy; return pt; } Parameters:
   r - angle in radians
   a - determines how far away from the center the spiral starts from
   b - determines density of each round of the spiral
   dir - direction of spiral (1 for clockwise, -1 for counter-clockwise)
   cx,cy - center point of spiral

This logSpiral function returns a point on the spiral at a particular angle. To use this, just increase the angle and use the points that it returns creates a spiral. Play with the parameters to see the spirals it creates:

Playing with the parameters, I was able to create some pretty interesting patterns.
It's generative art! Quite fun eh?

2 comments:

  1. GonçaloMiguel1/29/2012 6:27 PM

    MasterGod speaking !
    It´s golden.
    Thanks for sharing.
    I actually gonna try to get there.

    Gotta see that parameters shuffling around ;)

    Will Keep in contact.

    ReplyDelete
  2. Really cool stuff! Is there a function that also take speed into account? For example, a script that not only draws this spiral, but can also adjust speed (maybe have a logarithmic speed growth, etc.). Thanks for your help!

    ReplyDelete