Sign in to follow this  

3D object acceleration

Recommended Posts

Hello I want to simulate a throun object and how it falls. I have speed x, y and z; and curent x, y and z position, and the mass of the object. What are the formulas I should use to calculate how it travels, changes its speed and position. Thanks.

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
There is a formula that can describe the position exactly given a time. Like what is the position after 3.45 second. But I am not sure if you want to use this.

What I do is I calculate the frame using a small time unit. Calculate the net force (sum of all the forces acting on the mass) and then devide this with the mass to get your acceleration on the mass. Once you have your acceleration you can caculate the added speed using xspeed = xspeed + xaccel * time, yspeed= yspeed + yaccel*time. Once you have your speed you caculate position with xpos = xpos + xspeed * time, ypos=ypos + yspeed * time. This is a hack and in real life physic the time unit is infinitely small.

Say in your situation there is a force acting on the mass. Let force_x=0, force_y=mass * gravity_constant, force_z = 0. Add all your force together creating a net force. In this case you have only one. Once you have your net force caculate the position as above describe.

Why using the second method. It is easier to modified when there is more then one force.

Share this post

Link to post
Share on other sites
You can do this easily with vector math;
the base for your acceleration system is a vector from start / current position to the target position, which you will normalize after retrieving it.

As thrown objects movements has to be split up into one accelerated movement (the movement along the y-axis) and a constant velocity movement (the movement in relative to the x-z-plane), you will have to multiply the resulting y-velocity with your y-component of the normalized vector.
For the constant velocitiy movement, your velocity is a scalar, and your x-z components simply map the sine and cosine of the angle between your (orthogonal) plane and the start-target vector; so all you will have to do is multiply both x and z components with the constant velocity.

start position s = [xs, ys, zs]
target position t = [xt, yt, zt]
vector s->t = u = [xt - xs = xu, yt - ys = yu, zt - zs ) = zu]
normalized u0 = u / |u|

velocity va(t) defines your y-axis velocity over time
velocity vp(t) defines your (constant) x-z plane velocity over time

so we end up with
new position s' = s + v(delta t)
where v is the 'delta position' as a vector function of time difference (t2- t1)
v's component equations are following ones:
vx(t) = vp(delta t) * xu0
vz(t) = vp(delta t) * zu0
vy(t) = va(delta t) * yu0

Share this post

Link to post
Share on other sites
Merging the AP and lucem's reply and adding some salt and pepper gives you a complete solution: (In the following bold letters denote vectors.)

Get the current time (with a suitable resolution) each time you render a frame. Compute the difference of the current time and the prior one to get the elapsed duration T since the last recent rendering.

Sum all acting forces:
F := Σi Fi
In your example there is only one, namely gravity (I assume earth gravity here)
F1 = G := m * g = m * g * (0,-1,0)T
assuming gravity pulls masses in direction of negative cardinal y.

Divide the resulting force by the mass of the thrown object to yield the acceleration. In your example only the acceleration due to gravity is there:
a := F / m = g

Now integrate the acceleration to get the velocity
v += a * T
and integrate the velocity to get the position
p += v * T
(Notice that there are better working integration methods out there.)

You need to have initial conditions to initialize p(0), v(0), and a(0). In your example it seems best to use
a(0) := 0
v(0) := v(0) * u
p(0) := "where the thrown object has left the thrower"
where u denotes a given initial throw direction, and v(0) a given start speed.

You have to do some kind of collision detection to stop the motion somewhere. E.g. stop it of the thrown object's y co-ordinate falls below 0 (or verbosely: "it touches the ground").

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this