freenity 144 Report post Posted March 11, 2006 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. 0 Share this post Link to post Share on other sites
Guest Anonymous Poster Report post Posted March 11, 2006 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. 0 Share this post Link to post Share on other sites
lucem 176 Report post Posted March 12, 2006 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 timevelocity vp(t) defines your (constant) x-z plane velocity over timeso we end up withnew 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) * xu0vz(t) = vp(delta t) * zu0vy(t) = va(delta t) * yu0 0 Share this post Link to post Share on other sites
haegarr 7373 Report post Posted March 12, 2006 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} F_{i}In your example there is only one, namely gravity (I assume earth gravity here)F_{1} = 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 = gNow integrate the acceleration to get the velocityv += a * Tand integrate the velocity to get the positionp += 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 usea(0) := 0v(0) := v(0) * up(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"). 0 Share this post Link to post Share on other sites
freenity 144 Report post Posted March 12, 2006 Thanks to everybody. It really helped. 0 Share this post Link to post Share on other sites