This demo here shows the path of a particular body when it is set in a projectile motion at a certain angle with some initial velocity. The path shows the motion of the body in the next **3** seconds (it can be increased).

We will use a simple formula for projectile motions which goes like this: **S = P + u*t + 0.5*a*t*t**. Here S = Distance Travelled, P = Original Position, u = Initial Velocity, t = Time after which position has to be found out, a = Acceleration.

Where

a = world.GetGravity();

I have used the world time step of 1/60 seconds which means everytime update function is called the world steps by 1/60 seconds. Since I have used a frame rate of 60 (fps), each second 60 times

**update()**is called and hence

**step()**is also called 60 times. This means that in 1 second world steps by 60*(1/60) = 1 second. So in update function, I run a

**for loop**180 times and on each iteration the time 't' in the formula is increased by (1/60). This time 't' is fed to the motion formula and we get the position of the body after each 1/60 seconds. On each iteration we draw a

**point**on the canvas to track its position. After completion of all iterations we can see all the dots, representing the path of the center of the body.

Another thing which has been done here is to detect if the path of the body (within 3 seconds) overlaps with a body. To check that we will use

**RAYCASTING**. The first point will be the previous point (trajectory point calculated in previous iteration) and current point (trajectory point calculated in current iteration). If there is a body present between these two points, we'll calculate the intersection point and stop the iteration using

**break**command.

Here is a demo of

**TRAJECTORY**in Box2dweb.

PS: Please read the iforce2d.net's article on

*Projected Trajectory*.NOTE: If anyone needs a tutorial on this, please leave a

*comment*or*Reply*.