Constant speed
|
04-04-2016, 10:33 PM
Post: #1
|
|||
|
|||
Constant speed
I recently came accross this simple question which I found difficult to answer.
Consider the very common function y=sin(x). When you draw it with a computer, you see that the plot is accelerating or decelerating. Nothing surprising since the derivate of sin is cos. Now suppose you want to do an animation showing an ant walking on your sinus at constant speed. What would then be the equation to draw this? Can you find a general answer applicable for any equation? |
|||
04-05-2016, 07:01 AM
Post: #2
|
|||
|
|||
RE: Constant speed
Maybe the arc length of sin(x) can be the first step to the solution?
s= \(\int_{0}^{2\pi} \sqrt{1+cos^2(x)} dx \) Bernhard That's one small step for a man - one giant leap for mankind. |
|||
04-05-2016, 07:19 AM
(This post was last modified: 04-05-2016 07:24 AM by Tugdual.)
Post: #3
|
|||
|
|||
RE: Constant speed
For those who wonder, I have actually found a pretty comprehensive answer here
https://www.geometrictools.com/Documenta...dSpeed.pdf This little problem surprises me, because a very simple and natural question related to our everyday life (ex: driving a car on a road) ends up into something much more complex than expected. I actually started thinking about this question when I played the PopCap game Zuma with balls rolling on a curve. |
|||
04-05-2016, 11:14 AM
Post: #4
|
|||
|
|||
RE: Constant speed
(04-05-2016 07:19 AM)Tugdual Wrote: I actually started thinking about this question when I played the PopCap game Zuma with balls rolling on a curve. You're not the only one that's a complete nerd even while playing video games. Geometry Wars always gets me thinking about logarithms and exponential growth... |
|||
04-05-2016, 06:04 PM
Post: #5
|
|||
|
|||
RE: Constant speed
(04-05-2016 11:14 AM)Dave Britten Wrote:Glad to know I'm not alone(04-05-2016 07:19 AM)Tugdual Wrote: I actually started thinking about this question when I played the PopCap game Zuma with balls rolling on a curve. How about the liquid flow simulation in Pixel Junk Shooter? There is some material on the net explaining how this was done and it is really interesting. Game makers are very technical and knowledgeable people. |
|||
04-06-2016, 11:16 AM
Post: #6
|
|||
|
|||
RE: Constant speed
(04-05-2016 06:04 PM)Tugdual Wrote: Glad to know I'm not alone Yeah, that one always makes my head spin when I'm playing it. I'm guessing it's some kind of particle system under the hood, but I'm definitely not a game physics programmer. Just doing a decent Breakout engine without the ball passing through solid objects is tough enough. |
|||
04-07-2016, 06:13 AM
Post: #7
|
|||
|
|||
RE: Constant speed
(04-06-2016 11:16 AM)Dave Britten Wrote: Yeah, that one always makes my head spin when I'm playing it. I'm guessing it's some kind of particle system under the hood, but I'm definitely not a game physics programmer. Just doing a decent Breakout engine without the ball passing through solid objects is tough enough.Some reading for you: http://fumufumu.q-games.com/gdc2010/shooterGDC.pdf This document describes the version on PS3 operating with cells. Not sure how the PC version was done, it must have gone through heavy reprogramming. Amazing stuff, truly. |
|||
04-07-2016, 11:16 AM
Post: #8
|
|||
|
|||
RE: Constant speed
(04-07-2016 06:13 AM)Tugdual Wrote: Some reading for you: That's pretty close to how I imagined they were doing it: particles with fuzzy collision detection, to oversimplify it. The PS3's Cell processor is something like a 7-way parallel chip, and I've heard it described as resembling programming a DSP. The PC version probably gets away with running the simulation on whatever (more recent) CPU cores it has available, or maybe offloading some of it to the GPU. I'm guessing it's the former, since they also got Shooter running on the Vita, which is nowhere near as powerful as the PS3 in terms of number crunching. |
|||
04-11-2016, 02:01 PM
Post: #9
|
|||
|
|||
RE: Constant speed
The function \(y=sin(x)\) has the slope \({dy\over dx}=cos(x)\) which yields
\[dy=cos(x) \cdot dx\] The arc length of a segment with components \(dx\) by \(dy\) is given by \[ds = \sqrt{dx^2+dy^2}\] Substituting \(dy\) into the above yields \[ds = \sqrt{dx^2+(cos(x) \cdot dx)^2}\] and solving for \(dx\) gives \[dx = {ds \over \sqrt{cos(x)^2 + 1}}\] For any station \(x\) this defines the required \(dx\) to obtain the desired \(ds\). Useful for plotting curves using constant segment lengths or constant speed driving on a curved road ;-) The "General" answer depends on the equation - not all have simple Solutions for \(dx\). Then some nonlinear solver resp. iteration would be needed. |
|||
04-11-2016, 03:53 PM
Post: #10
|
|||
|
|||
RE: Constant speed
(04-11-2016 02:01 PM)Martin Hepperle Wrote: The function \(y=sin(x)\) has the slope \({dy\over dx}=cos(x)\) which yieldsThanks Martin, sounds like a good answer but I struggle with further conclusions. First, at constant speed, I would assume that ds/dt = 0 so dx = 0? Other question is how do you move from your expressions to a parametric equation for x(t) and y(t) over the time? |
|||
04-13-2016, 03:29 PM
(This post was last modified: 04-13-2016 03:30 PM by Martin Hepperle.)
Post: #11
|
|||
|
|||
RE: Constant speed
(04-11-2016 03:53 PM)Tugdual Wrote: ... Almost ... constant speed would be \(v = {ds \over dt} = const.\) not zero. where: \(ds\) ... distance and, \(dt\) ... time interval. Using a given (constant) speed \(v\) and a (user selected) time step \(dt\) you would determine \(ds = v \cdot dt\) and then use the equation above to find \(dx\). You would start at e.g. time \(t=0\) at position \(x=0\), calculate \(dx\) for the given speed, march to \(x=x+dx\) and plot \(f(x)\) at the new point (for time \(t=t+dt\). Then repeat for the next time step. My simple equations will work as long as the function is monotonic \(y=f(x)\). For a parametric curve (e.g. a circle) one would have to rewrite with the parameter \(t\) or \(s\) (arc length) to obtain \(dx\) as well as \(dy\) as a result. This is left as an exercise to the inclined reader ... ;-) Martin |
|||
04-13-2016, 06:30 PM
Post: #12
|
|||
|
|||
RE: Constant speed | |||
04-18-2016, 07:27 AM
(This post was last modified: 04-18-2016 08:07 AM by Martin Hepperle.)
Post: #13
|
|||
|
|||
RE: Constant speed
... and for illustration ... a Series-80 BASIC implementation for drawing a curve at "constant speed". You supply the two functions for x(p) and y(p) at the end of the code.
Besides the pure plotting data some additional values are calculated (e.g. the arc length of the curve). For speed you could strip some code and I also have left in some duplicated subexpressions for clarity. The ticks option can be used to draw monorail tracks if you want to describe the track layout mathematically... Code:
Of course, one could replace \(arctan()\), \(sin()\) and \(cos()\) by \(sqrt()\) expressions and simplify further. Then you could replace Code:
The implementation will also hang if both derivatives are zero at the same time (singular point). Martin |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)