PDA

View Full Version : Need Help Generating Logarithmic Spiral


trohoang
07-13-2006, 04:53 AM
Hi there,

Has anyone generated a code for creating a logarithmic spiral? I am having lots of problems with this....

ealbrecht
07-14-2006, 01:42 AM
This is doing using Flash Actionscript. Now ideally I would only want to plot like 10 xy coordinates and then use a curveTo() function to curve the line to each corresponding xy coordinate in the Array. Well, I'm not sure how to calculate my control points yet for the anchor points for the curveTo function. This example uses several hundred points with simple lineTo function.

DrawSpiral();


function DrawSpiral() {
var points:Array = new Array();
var b:Number = DegToRad(80);
var r:Number;
var t:Number;
var i:Number;
var a:Number = 1;


for (i=0; i<=500; i++) {
t = a * Math.PI/4;
r = Math.exp(t * cot(b));
points[i] = new Object();
points[i].r = r;
points[i].x = r * Math.cos(t);
points[i].y = r * Math.sin(t);
a+=0.2;
}

with (spiral_mc) {
lineStyle(0.5,0xff0000);
moveTo(points[0].x, points[0].y);

for (i=1; i<=500; i++) {
lineTo(points[i].x, points[i].y);
}
}
}


function DegToRad(degrees:Number) {
return degrees * Math.PI/180;
}
function cot(t:Number) {
return 1 / Math.tan(t);
}

If you can figure out how to easily calculate the control points for the curveTo function then that'll simply and greatly speed up things.

trohoang
07-15-2006, 01:27 AM
Hi ealbrecht,

Thank you very much for your prompt reply. I will give it a try and let you know the results.

Many thanks,