Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Dec 2008
    Location
    Tannhäuser Gate
    Posts
    286
    Thanks
    7
    Thanked 58 Times in 57 Posts

    Parametric equations for butterfly curve.

    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:
    Code:
    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.
    Last edited by freedom_razor; 03-13-2009 at 01:54 AM.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,147
    Thanks
    203
    Thanked 2,547 Times in 2,525 Posts
    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.

  • Users who have thanked Philip M for this post:

    freedom_razor (03-12-2009)

  • #3
    Regular Coder
    Join Date
    Dec 2008
    Location
    Tannhäuser Gate
    Posts
    286
    Thanks
    7
    Thanked 58 Times in 57 Posts
    Nice one. Do you mind posting the link, 'cos [shame on me] searching as I was, I still haven't come upon that info.

  • #4
    New Coder
    Join Date
    Mar 2009
    Location
    Fabric Covered Box
    Posts
    69
    Thanks
    1
    Thanked 16 Times in 14 Posts
    In javascript, ^ is the bit-wise exclusive-or opererator. For exponentiation, use Math.pow
    Code:
    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) )

  • The Following 2 Users Say Thank You to Shannon Blonk For This Useful Post:

    freedom_razor (03-12-2009), Philip M (03-13-2009)

  • #5
    Regular Coder
    Join Date
    Dec 2008
    Location
    Tannhäuser Gate
    Posts
    286
    Thanks
    7
    Thanked 58 Times in 57 Posts
    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.
    Last edited by freedom_razor; 03-13-2009 at 01:53 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •