V
V
V Sh.2017-09-21 07:17:42
Mathematics
V Sh., 2017-09-21 07:17:42

What formulas can describe the movement of an object?

Good day!
Please tell me how to algorithmically implement the movement of an object like the movement of a pokeball from the game "Pokemon GO"? In short, we move our finger across the smartphone screen (swipe), and the pokeball (ball) flies in the right direction with the right speed and rotation. If we do a slow swipe, then the ball flies more slowly. If we make a swipe with an arc, then the ball twists in an arc.
Now I have an array containing the coordinates of the swipe points and the time when the pointer (finger) was in these coordinates. How can I create a mathematical model of movement using these points? Do you need to somehow translate statics into dynamics (speed, rotation, then add gravity)?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander Skusnov, 2017-09-21
@AlexSku

I don't know where you get the information from, at one time in Delphi the information came from gestures.
You described the rest well (remember? - setting a problem is half the solution), you just need to structure it better.
Initial data first.
Then write the equations of displacement and rotation (velocity - integral (i.e. accumulation) of acceleration, displacement - integral of velocity), you can add gravity and friction. Substitute the original data - and get the result depending on the time. Do animation (position, rotation) at the right time.

X
x67, 2017-09-21
@x67

An object has a velocity vector and an acceleration vector. There is also one angular velocity (on a plane) and one angular acceleration.
Actually, let's analyze a simple case when, when swiping, the object instantly reaches the desired speed and the desired rotational speed.
Then you can approximate a swipe to a line (queries: linear filtering, trend by points, linear interpolation, etc.). It may be ok to just take the start and end point, try it. Then the speed of the object along the X axis will be equal to (x2-x1)*К/(t2-t1), where 1 and 2 are the start and end points of the swipe, and K is some coefficient that will be convenient for you. And along the Y axis, respectively (y2-y1)*K/(t2-t1).
Consider twist. Take the start and end points of the swipe, get a line out of them, then look for the farthest point from the line (or for simplicity, look for the distance of the midpoint to the line). The angular velocity will be proportional to this distance.
How to make things accelerate smoothly?
First of all, you need to remember that the acceleration should not be constant, there should be some kind of inflation in time. And fast. Next, you need to decide if the objects have a different mass (how physical is the game?) If not, then we work directly with acceleration, if there is, then there will be another force acting on the object. Suppose there is no mass, then you can make a simple acceleration equal to some number. We also consider the final speed, but at the same time we do not immediately assign the speed, but gradually change it according to the following formula:Vx=Vx+ax*dt. dt - interval between frames (for devices with variable fps, so that the game does not jump,) ah - acceleration along the x axis. When the speed is reached, the acceleration becomes zero.
Another option for smooth acceleration is Vx=K*Vx+(1-K)*Vxzad, where K can be in the range from 0 to 1, and Vxzad is the estimated speed to be reached. The more K, the slower the object will accelerate. If necessary, this formula can be written in a slightly different form, then it will be more pleasant to work with it (it will be easy to set how long the object will reach its speed).
For angular velocity, all this works exactly the same.
Well, yes, in principle, you can do without acceleration or forces with mass, setting the speed algorithmically, but with acceleration it will be convenient to introduce various effects like gravity, friction, etc.

G
Griboks, 2017-09-21
@Griboks

Judging by the condition, there is already r(t) - the movement function obtained from the movement of the finger across the screen. It is necessary to make a similar movement for the pokeball.
1) The movement of the ball along an arc and another trajectory defined by the user.
I suggest simply simply scaling your r(t) to the desired size and launching a ball over it.
( Relevant transformations )
2) Gravity
The easiest way is to move the ball in two iterations: r(t) and then apply gravity [y(t) = y0 + V0*t + 5*t^2]. Don't forget it's pointing down!
3) Rotation
It is necessary to determine how the user will set the rotation. After all, a swipe in an arc is the movement of a ball in an arc. But, for example, it will not be difficult to rotate the ball with the angular velocity w=r(tmax)-r(tmin).
4) More accurate models
Of course, you can also calculate the resistance forces, speeds, jerks, mass, energy and much more. Only it is not required at all in this task.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question