OZONE Asylum
Forums
Multimedia/Animation
Rotating an object along a curve
This page's ID:
29006
Search
QuickChanges
Forums
FAQ
Archives
Register
Edit Post
Who can edit a post?
The poster and administrators may edit a post. The poster can only edit it for a short while after the initial post.
Your User Name:
Your Password:
Login Options:
Remember Me On This Computer
Your Text:
Insert Slimies »
Insert UBB Code »
Close
Last Tag
|
All Tags
UBB Help
Let me restate the problem so I'm sure I understand what you said: You want to display an arrow traveling along a sine curve and you want the arrow to point along the tangent of the curve as it travels. If that is a correct restatement of your problem, the solution is relatively simple. It involves a little calculus, but you don't need to understand calculus to understand the solution. The tangent of any function is defined as the first derivative of that function. Since your function is f(x) = sin(x), the first derivative is f'(x) = cos(x). The tangent of the curve at any given point is the slope of the curve of that point. That is to say that a straight line with the same slope as the tangent to the curve will touch the curve at a single point. (This isn't quite true for curves such as sin because if you make the line long enough it may touch the curve at multiple point so what we are really talking about is a local tangent and that is what you are interested in here.) Lets pick a point [i]a[/i] on the x-axis where you want to draw your arrow. To draw your arrow moving along the curve, you will later solve the following for a range of a values and display the arrow at each of the chosen [i]a[/i]s, but for now we will work with only one [i]a[/i]. Since the first derivative of f(x) = sin(x) is f'(x) = cos(x) we can find the slope of the tangent to f(x) at [i]a[/i] as f'(a) = cos(a). This gives you the slope of a straight line that is tangent to sin(x) at [i]a[/i]. We know that the function for a straight line is y = m*x + b where [i]m[/i] is the slope of the line and [i]b[/i] is the value at which the line crosses the y-axis. So, we can substitute the slope of out tangent into this equation and get y = cos(a)*x + b. We also know that the straight line passes through the point (a, sin(a)) because that is the point where the line is tangent to f(x) = sin(x). Substituting this point into the equation we get sin(a) = cos(a)*a + b. This gives an equation for [i]b[/i] b = a * sin(a)/cos(a) = a * tan(a) From this we substitute back into our original equation for a line (y = m*x + b) giving y = cos(a)*x + a*tan(a). Now you can pick two points on ether side of [i]a[/i] and use those points to draw the arrow along the sine curve. Let's pick a point that is [i]d[/i] to the left of [i]a[/i] and another that is [i]d[/i] to the right of [i]a[/i]. y1 = (a-d) * cos(a) + a*tan(a) y2 = (a+d) * cos(a) + a*tan(a) Now draw an arrow from (y1, a-d) to (y2, a+d) and you have drawn one arrow along the curve. Put this into a loop for a=min_a to max_a by a_step { y1 = (a-d) * cos(a) + a*tan(a) y2 = (a+d) * cos(a) + a*tan(a) Draw_Arrow((y1, a-d), (y2,a+d)) } Your arrow will travel along the sine curve and point along the tangent of the curve. Note that if you change f(x) to another function, you can find the first derivative of that function and use this same method to create an arrow that will travel along that curve as well. . -- not necessarily stoned... just beautiful. [url=http://www.hyperbole-software.com/] [img]http://www.hyperbole-software.com/ozone/hyperbole-88x33.gif[/img] [/url]
Loading...
Options:
Enable Slimies
Enable Linkwords
« Backwards
—
Onwards »