-
Bearded (M|G)od
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
-
Bearded (M|G)od
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)).
-
Bacon-wrapped closures
cool, thanks for posting. I saw your question a couple days ago and wanted to know the answer myself.
-
imagination through stupidity
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.
-
Bearded (M|G)od
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.
-
imagination through stupidity
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.
-
Now tell me whos watchin......
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|