Calculating tangent of a point on sine curve.

Started by
6 comments, last by GameDev.net 19 years, 8 months ago
Hi! I've created an opengl animation of a sine wave. The wave is made of polys on which I'd like to slap a texture. I need to know what is the orientation of the poly and also I've found the curve doesn't have the expected thickness everywhere. I want to find the tangent of an arbitrary point, and then get the vector perpendicular at that point. I think I can solve all my problems with this. The big question is, how can I obtain the tangent? It seems this could be done by calculating (integrating?) the following limit: ( sin(qx) - sin(px) ) / ( qx - px ) Is there an easier way around? Thanks!
Advertisement
The slope of the tangent to a function's curve at one point is the value of the derivative of the function at that point.

The derivative of sin(x) is cos(x) (and the derivative of cos(x) is -sin(x))

The equation of your tangent at x0 should be y = cos(x0) * (x-x0) + sin(x0)
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Use the derivative of sin(x) which is cos(x) (the slope of the tangent to the curve), you can get the angle of the tangent with atan(cos(x)). With your limit, you are numerically doing the same, cos(x) is more accurate.
Here's an answer that might more more sense for you. The derrivative of the function is the answer to the analytic tangent, but like you said, that's not the easiest way out.

I'm guessing that you are tesselating the curve into a set of vertices to render correct? You basically have a string (set of connected vertices), which describe your curve in 3D. In such a case, you are not really dealing with a cosine/sine but with a set of line segments. It's pretty easy to compute the tangent vector for a line. It's a bit more tricky for a 3D curve. Fortunately, Chapter 14 of "Mathematics for Game Developers" p.400 has all the details you'll need on the subject if you want to take a look at that; since you do have the book.
The Derivative of Sin(x) is Cos(x).
The Derivative of Cos(x) is -Sin(x).
The Derivative of Tan(x) is Sec(x) * Sec(x)

However, all these trig derivatives only work if x is in radians.
(To convert to radians from degrees you must take the degrees and multiply it by (PI / 180))
"..."
Have you checked out NeHe's vertex shader tutorial? That could be very easily modded to serve your purposes as well.
My fellow Americans I have just signed legislation that outlaws Russia forever. Bombing will commence in five minutes.
Generally, in order to get the actual sine wave, you need to be in radians, anyways, though.
What exactly are the numbers p and q?

This topic is closed to new replies.

Advertisement