Constant speed - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: General Forum (/forum-4.html) +--- Thread: Constant speed (/thread-5983.html) |
Constant speed - Tugdual - 04-04-2016 10:33 PM 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? RE: Constant speed - PANAMATIK - 04-05-2016 07:01 AM 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 RE: Constant speed - Tugdual - 04-05-2016 07:19 AM For those who wonder, I have actually found a pretty comprehensive answer here https://www.geometrictools.com/Documentation/MovingAlongCurveSpecifiedSpeed.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. RE: Constant speed - Dave Britten - 04-05-2016 11:14 AM (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... RE: Constant speed - Tugdual - 04-05-2016 06:04 PM (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. RE: Constant speed - Dave Britten - 04-06-2016 11:16 AM (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. RE: Constant speed - Tugdual - 04-07-2016 06:13 AM (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. RE: Constant speed - Dave Britten - 04-07-2016 11:16 AM (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. RE: Constant speed - Martin Hepperle - 04-11-2016 02:01 PM 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. RE: Constant speed - Tugdual - 04-11-2016 03:53 PM (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? RE: Constant speed - Martin Hepperle - 04-13-2016 03:29 PM (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 RE: Constant speed - Tugdual - 04-13-2016 06:30 PM (04-13-2016 03:29 PM)Martin Hepperle Wrote: Almost ... constant speed would be \(v = {ds \over dt} = const.\) not zero.oOops, my bad, I'm definitely rusty. Thanks for the clarification Martin! RE: Constant speed - Martin Hepperle - 04-18-2016 07:27 AM ... 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 |