A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Line Tangent to a point on a Sine Curve

  1. #1
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045

    Line Tangent to a point on a Sine Curve

    I have a curve drawn using a sin function. How can I draw the line tangent to a point, when say x=20. This is how my sine wave is being drawn:
    Code:
    var amplitude:Number = 100;
    var phase:Number = .5;
    var x_shift:Number = 0;
    var y_shift:Number = 100;
    var accuracy:Number = 5;
    
    
    for(var x:Number=0; x<100; x+=accuracy)
    {
       placeDot(x, amplitude*Math.sin(phase*x-x_shift)+y_shift);
    }
    
    //placeDot function just puts a movieclip at the x, y coordinates
    I've determined that I need to calculate the first derivative of the function, but after looking at all these math calculations, I have no idea how to translate that into Flash. Basically I want to be able to pick a point on the graph and draw the tangent line.

    Thanks

  2. #2
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    Ehh, I got it. The slope at any point is just Math.cos(phase*x-x_shift), then the angle is Math.atan(Math.cos(phase*x-x_shift)).

  3. #3
    Bacon-wrapped closures Nialsh's Avatar
    Join Date
    Dec 2003
    Location
    Houston!
    Posts
    338
    cool, thanks for posting. I saw your question a couple days ago and wanted to know the answer myself.

  4. #4
    imagination through stupidity
    Join Date
    Apr 2001
    Location
    P3X-3113
    Posts
    1,238
    Hey Taco,

    I've been having a problem. Apparently Math.tan returns some sort of inverted cartesian plane calculation of tan? Why is that and how do I adjust for it so i can get the real tangent of a number ( like in my calculator )?
    Nothing to see here, move along.

  5. #5
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    Flash calculates all of the math functions in radians. You are probably looking for degrees?

    Radians to degrees just works as follows: degrees = radian*180/PI

    So for example, if you are looking for angle A of a right triangle ABC, where B is a right angle, Math.atan(AB/BC) is going to yield radians. You want the degrees, so you can do: (Math.atan(AB/BC)*180)/Math.PI and you'll have degrees.

    I hope that answers your question.

  6. #6
    imagination through stupidity
    Join Date
    Apr 2001
    Location
    P3X-3113
    Posts
    1,238
    Yea, I figured that out. Can't believe that I had forgotten that. I have to convert my degrees to radians and do Math.tan(radians).

    Thanks.
    Nothing to see here, move along.

  7. #7
    Now tell me whos watchin...... samvillian's Avatar
    Join Date
    Feb 2007
    Location
    Where do you live?
    Posts
    539
    thanks alot very useful

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center