Projectile Motion from a Building: 2D Trajectory Explorer

March 26, 2026

Problem

A ball is thrown from the top of a building of height 20 m with an initial velocity of 15 m/s at an angle of 30° above the horizontal.

Explanation

We model the motion of a ball thrown from the top of a building using standard projectile motion equations.


Problem Setup

A ball is thrown from the top of a building:

  • Building height: h0=20mh_0 = 20\,\text{m}
  • Initial speed: v0=15m/sv_0 = 15\,\text{m/s}
  • Launch angle: θ=30\theta = 30^\circ above the horizontal
  • Gravitational acceleration: g9.8m/s2g \approx 9.8\,\text{m/s}^2 (downward)

We assume:

  • No air resistance
  • Constant gravitational field
  • 2D motion (horizontal xx and vertical yy)

We choose the origin at the base of the building, with:

  • xx axis: horizontal, positive to the right
  • yy axis: vertical, positive upward

Thus the ball starts at (x0,y0)=(0,20)(x_0, y_0) = (0, 20).


Decomposing the Initial Velocity

The initial velocity vector v0\vec v_0 is split into horizontal and vertical components:

v0x=v0cosθv0y=v0sinθ\begin{aligned} v_{0x} &= v_0 \cos\theta \\ v_{0y} &= v_0 \sin\theta \end{aligned}

For v0=15v_0 = 15 and θ=30\theta = 30^\circ:

cos30=320.866,sin30=12=0.5\cos 30^\circ = \frac{\sqrt{3}}{2} \approx 0.866,\quad \sin 30^\circ = \tfrac{1}{2} = 0.5

So:

v0x150.86612.99m/sv0y=150.5=7.5m/s\begin{aligned} v_{0x} &\approx 15 \cdot 0.866 \approx 12.99\,\text{m/s} \\ v_{0y} &= 15 \cdot 0.5 = 7.5\,\text{m/s} \end{aligned}

Position as a Function of Time

Ignoring air resistance, the horizontal motion is uniform, and the vertical motion is uniformly accelerated.

Horizontal position:

x(t)=x0+v0xt=v0xtx(t) = x_0 + v_{0x} t = v_{0x} t

(since we choose x0=0x_0 = 0).

Vertical position:

y(t)=y0+v0yt12gt2y(t) = y_0 + v_{0y} t - \tfrac{1}{2} g t^2

with y0=20y_0 = 20.

So explicitly:

x(t)=v0cosθ  ty(t)=20+v0sinθ  t12gt2\begin{aligned} x(t) &= v_0\cos\theta \; t \\ y(t) &= 20 + v_0\sin\theta \; t - \tfrac{1}{2} g t^2 \end{aligned}

Time of Flight (Landing Time)

The ball hits the ground when y(t)=0y(t) = 0.

Solve

0=20+v0sinθ  t12gt2.0 = 20 + v_0 \sin\theta \; t - \tfrac{1}{2} g t^2.

This is a quadratic in tt:

12gt2+v0sinθ  t+20=0.-\tfrac{1}{2} g t^2 + v_0 \sin\theta \; t + 20 = 0.

Multiply by 1-1 for convenience:

12gt2v0sinθ  t20=0.\tfrac{1}{2} g t^2 - v_0 \sin\theta \; t - 20 = 0.

Using the quadratic formula at2+bt+c=0at^2 + bt + c = 0 with:

  • a=12ga = \tfrac{1}{2}g
  • b=v0sinθb = -v_0 \sin\theta
  • c=20c = -20
t=b±b24ac2at = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}

Plugging in values (keeping it symbolic here):

t=v0sinθ±(v0sinθ)2+2g20g.t = \frac{v_0 \sin\theta \pm \sqrt{(v_0\sin\theta)^2 + 2 g \cdot 20}}{g}.

There will be two solutions, one negative (non-physical for forward time) and one positive. We take the positive root as the total time of flight TT.

Once TT is known, the horizontal range is:

R=x(T)=v0cosθ  T.R = x(T) = v_0 \cos\theta\; T.

The visualization computes this time numerically and shows:

  • The full trajectory curve from t=0t = 0 to TT.
  • The ball position at an animated time tanimt_\text{anim} that loops from launch to landing.

Understanding the Visualization

This interactive canvas shows:

  • A dark background with neon curves for the trajectory.
  • A building on the left with its height representing 20m20\,\text{m}.
  • The ball moving along the parabolic path.
  • Vector arrows for the initial velocity components, v0xv_{0x} and v0yv_{0y} (when toggled on).
  • (Optionally) a faded ghost trajectory for reference while you change parameters.

Controls

  • Initial Velocity (m/s): Changes v0v_0 and therefore both range and maximum height.
  • Angle (degrees): Changes θ\theta, controlling how much of v0v_0 is vertical vs horizontal.
  • Gravity (m/s²): Adjusts gg, letting you explore motion on different planets.
  • Time Scale: Speeds up or slows down the animation in time.
  • Show Vectors: Toggles the display of the initial velocity components.
  • Show Full Path: Toggles the drawn full trajectory.

Cartesian vs Canvas Coordinates

The math uses a standard Cartesian system with yy positive upwards, but the HTML canvas has yy increasing downwards. To map physics coordinates (x,y)(x, y) to canvas (Xc,Yc)(X_c, Y_c), we use:

Xc=xoffset+xs,Yc=yoffsetys,\begin{aligned} X_c &= x_\text{offset} + x \cdot s, \\ Y_c &= y_\text{offset} - y \cdot s, \end{aligned}

where ss is a pixel-per-meter scale and the offsets place the origin near the ground at the base of the building.


How to Use This to Understand the Problem

  1. Start with the default values (15 m/s, 30°) and watch the trajectory.
  2. Increase the angle towards 90° to see more vertical motion and shorter horizontal range.
  3. Decrease the angle towards 0° to see a flatter, more horizontal throw from the building.
  4. Change gravity to see how the same initial throw behaves on different worlds (e.g., Moon vs Earth).

Under the hood, the animation simply evaluates:

x(t)=v0cosθ  t,y(t)=20+v0sinθ  t12gt2x(t) = v_0\cos\theta \; t, \quad y(t) = 20 + v_0\sin\theta \; t - \tfrac{1}{2} g t^2

for many points in time between t=0t=0 and the landing time TT, and then maps these coordinates to the canvas for drawing the smooth path and the moving ball.

Interactive Visualization

Parameters

15.00
30.00
9.80
1.00
Projectile Motion from a Building: 2D Trajectory Explorer