Sunday, February 28, 2016

physics - Determing an object's position along a curve over time


I have some objects in my game which are "thrown". At the moment I am trying to implement this by having these objects follow a parabolic curve. I know the start point, the end point, the vertex and the speed of the object.




  1. How can I determine at any given time or frame what the x & y co-ordinates are?

  2. Is a parabolic curve even the right curve to be using?



Answer



What your looking for a parametric plot of the parabolic function. It's easiest to make the parametric function use a range of p ∈ [0,1].


The canonical form for a parametric parabola is



k := some constant
f_x(p) = 2kp

f_y(p) = kp²



Using this formula and some basic algebra for function morphing and I got



p ∈ [0,1] → x,y ∈ [0,1]
or in other words keep p between 0 and 1 and x,y will be between 0 and 1 as well.
x = p
y = 4p - 4p²



So to get these functions will produce the numbers you're looking for.



float total_time = 2;
float x_min = 0;
float x_max = 480;
float y_min = 0;
float y_max = 320;

float f_x( float time )
{
float p = time/total_time;
return x_min + (x_max-x_min)*p;

}

float f_y( float time )
{
float p = time/total_time;
return y_min + (y_max-y_min)*(4*p-4*p*p);
}

No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...