View Full Version : Resolved Parametric equations for butterfly curve.

03-12-2009, 09:29 PM
I'm trying to construct parametric equations for butterfly curve in Javascript, but it's been a long time since my math classes and I don't really remember the stuff.
Anyway, I've got this:

x=Math.sin(t)*( (Math.exp(Math.cos(t))) - (2*Math.cos(4*t)) - (Math.sin(t/12)^5) )
y=Math.cos(t)*( (Math.exp(Math.cos(t))) - (2*Math.cos(4*t)) - (Math.sin(t/12)^5) )

Assuming that equations are right [I don't really know, I've tried to translate them to Javascript from some articles - corrections most welcome], what exactly I have to do with t?
I'm not sure what value should it have. I think it should be some kind of range of values, but I don't know exactly what range.
I've tried just slowly incrementing value [from 0, by .01], but the curve does not look like butterfly curve, similar maybe, but certainly it isn't butterfly.

Philip M
03-12-2009, 10:01 PM
Wow! Even longer since I did this!

A search tells me that t is a value within the range 0 and 24*pi

Try larger values such as 1 or 2 or 10 and see what you get.

03-12-2009, 10:20 PM
Nice one. Do you mind posting the link, 'cos [shame on me] searching as I was, I still haven't come upon that info.:confused:

Shannon Blonk
03-12-2009, 10:20 PM
In javascript, ^ is the bit-wise exclusive-or opererator. For exponentiation, use Math.pow

x=Math.sin(t)*( (Math.exp(Math.cos(t))) - (2*Math.cos(4*t)) - Math.pow(Math.sin(t/12),5) )
y=Math.cos(t)*( (Math.exp(Math.cos(t))) - (2*Math.cos(4*t)) - Math.pow(Math.sin(t/12),5) )

03-13-2009, 12:06 AM
Well, finally I left the range as it was, starting at 0, each iteration +0.01. The effect [reversed 180 degrees]:

Thanks again Shannon for pointing out my mistake. It made quite a difference.