User Tag List

Results 1 to 9 of 9

Thread: Need help with cosine wave math

  1. #1
    Clicker Multimedia Fusion 2

    Join Date
    Jun 2006
    Location
    Montreal, Canada
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need help with cosine wave math



    I have an Overlay object that renders part of a cosine wave.
    The function for that wave is:
    y = Cos( ( 90.0/w )*x )*h
    This function will scale the wave segment with the scale of the overlay.

    Now, I need a function that will output the total length [color:#CC0000]along[/color] the curve from point (0,h) to point (w,0).

    I also need two other functions to output the (x,y) position using a [color:#FF0000]distance input (d)[/color] along the curve starting at (0,h).
    (x,y) should be equal to (0,h) with a specified distance of 0.
    It should also be possible to get points on the cosine wave that are outside of the overlay object, with any large or negative distance values.

    Please let me know if you have any ideas for this.
    Thanks

  2. #2
    Clicker Multimedia Fusion 2

    Join Date
    Jun 2006
    Location
    Montreal, Canada
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Need help with cosine wave math

    I found links that give some formulas to get the "Arc length" of a curve segment, but I don’t understand some of those advanced math symbols. I have no idea how to apply them into MMF expressions.
    http://en.wikipedia.org/wiki/Arc_length
    http://www.mathwords.com/a/arc_length_of_a_curve.htm

    I'm sure these could help me get the curve length between two points, but I still don’t know how to get a point from a curve length.

  3. #3
    Clicker Multimedia Fusion 2 DeveloperHTML5 Export ModuleSWF Export ModuleInstall Creator Pro
    drnebula's Avatar
    Join Date
    Jul 2006
    Location
    Pennsylvania, USA
    Posts
    908
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Need help with cosine wave math

    You could approximate this length by breaking the curve up into small pieces and calculating the length of each small piece as if it were a straight line and using the distance formula. Let's say you wanted the length from x1 to x2. Break this into ten intervals. Then using your basic equation, find the y value for each of the ten itervals. Then calculate the length of each of these straight lines. This is basically what those equations you found are doing using calculus. Now, to be sure that this is workig, break the length down into 20 intervals. Usng loops, this shouldn't be too hard. Then 30 intervals. The results should start to approach a certain value. When you get very little change with more intervals, your answer is basically correct. I hope I have explained this clearly.
    STeve

  4. #4
    Clicker Multimedia Fusion 2

    Join Date
    Jun 2006
    Location
    Montreal, Canada
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Need help with cosine wave math

    That's one solution for getting the lenght, but I'm woried about it being an estimation. And I still have no idea how to get a position on the curve using a lenght, especially if it's going to be unprecise, which is what I mostly need really.

    I'm still searching about it though.

  5. #5
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleSWF Export Module

    Join Date
    Apr 2007
    Posts
    208
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Need help with cosine wave math

    Your best bet is an estimation since we are working with whole number entities; pixels. If your sine wave has been forged from pixels the smallest unit you can work with is 1 pixel, therefore using a linear stepwise method for estimating the length of the curve with a distance of 1 pixel is your best bet.

    Your alternative method is integration:

    Intergral(sqrt(1 + (dy/dx)^2)) - where y = cos x, between the limits you are interested in

    you can probably solve that using the substitution U = 1 - sin^2 x

  6. #6
    Clicker Multimedia Fusion 2

    Join Date
    Jun 2006
    Location
    Montreal, Canada
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Need help with cosine wave math

    :confused: You totally got me lost there...
    What is integral()? Because it’s not a function in MMF.
    And what is dx and dy? distance*x ?

    And as for the pixel thing, I rather think in terms of just "units" rather than actual pixels. Even if I ultimately have to output as pixel coordinates (which are integer values), I still need the precision of float values for function inputs. Because in the case of a cosine wave function, two different x input that have a small float difference can result in two different outputs with a larger integer difference.

  7. #7
    Clicker Multimedia Fusion 2 DeveloperHTML5 Export ModuleSWF Export ModuleInstall Creator Pro
    drnebula's Avatar
    Join Date
    Jul 2006
    Location
    Pennsylvania, USA
    Posts
    908
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Need help with cosine wave math

    I think what we need to know is what are you trying to do with these numbers? Does the user somehow move along the curve - then you can't be more accurate than one pixel. Or, is the user going to input an x position - in that case, you could calculate the answer mathematically to many decimal places. But no matter how you do it, there is always some error from the "actual" answer.
    Steve

  8. #8
    Clicker Multimedia Fusion 2

    Join Date
    Jun 2006
    Location
    Montreal, Canada
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Need help with cosine wave math

    Yeah, it's for objects that move along the curve.

    But objects will have to move with velocity. Not velocity along the x and y axis, but velocity along the curve’s axis relative to the point 0,0 and the curve’s function; As if the curve had its own local one-dimensional coordinate system that can be converted back into bi-dimensional coordinates.

    Also, the problem with looping through integer parameters with a cosine wave function, is that the output start to “skip points” where the slope become too steep.
    The result causes something like this, if I was to loop through x inputs for the function y = Cos( ( 90.0/w )*x )*h

  9. #9
    Clicker Multimedia Fusion 2

    Join Date
    Jun 2006
    Location
    Montreal, Canada
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Need help with cosine wave math

    All right, I have to resolve myself to the fact that I just can't get the curve length out of just one X position. I really might have to do some looping through numerous X positions and “accumulate” length values along the curve.

    But then this brings the issue of process speed.
    Frankly, I have no idea if one really complex rectangular equation is faster or slower than a series of loops. So I’m now thinking about using memory to speed up things.

    Basically, I plan on creating a 2D array for the curve. It will compute and store the values once with the proper loop and functions relative to each X positions. Then, getting the values of Y, Distance, and Angle will only be a matter of accessing them through array coordinates. This will require more memory, but it’s at a low cost compared to the cost of process required otherwise. And getting values out of the array will be very fast each time that it’s required.

    But I’m still researching for an effective “length of arc” equation, just in case I find something useful. I might try parametric equations and see if I can get the right solution there.

    I'll post an exemple file if I get it working properly.
    Closing thread.

Similar Threads

  1. 360 degree movement with Sin/Cosine 'wobble'
    By RobertRule in forum Multimedia Fusion 2 - Technical Support
    Replies: 5
    Last Post: 27th August 2011, 10:48 AM
  2. wave of bees...
    By UserIsSean in forum Multimedia Fusion 2 - Technical Support
    Replies: 1
    Last Post: 31st July 2009, 08:16 PM
  3. Wave problems
    By Kochicoro in forum Multimedia Fusion 2 - Technical Support
    Replies: 7
    Last Post: 15th January 2007, 10:04 PM
  4. Sin wave
    By Horn in forum Multimedia Fusion 2 - Technical Support
    Replies: 12
    Last Post: 6th December 2006, 06:38 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
  •