← Simulation & Statistics

Simulation & Statistics · Part 2 of 12

Flight without atmosphere

Given the following model we are going to simulate a flight trajectory without taking atmosphere into consideration

Handwritten model without air: vx = v0 cos α, vy = v0 sin α − g t, so x = v0 cos α · t and y = v0 sin α · t − g t² / 2

Result

The flight window before launch: height, angle and speed inputs set to zero, Launch and Pause buttons, and an empty chart

A launch at 45° and 25 m/s without air: a symmetric parabola that peaks near 16 m and comes down at about 60 m after 3.4 s

Implementation

First Model

C#
t = 0;
x0 = 0;
y0 = inputHeight.Value;
v0 = inputSpeed.Value;

double a = (double) inputAngle.Value * Math.PI / 180;

cosa = (decimal) Math.Cos(a);
sina = (decimal)Math.Sin(a);

chart1.Series[0].Points.AddXY(x0, y0);
timer1.Start();

Model on each unit of time

C#
const decimal dt = 0.1M;
const decimal g = 9.81M;

t += dt;
decimal x = x0 + v0 * cosa * t;
decimal y = y0 + v0 * sina * t - g * t * t /  2;

label4.Text = "Time: " + t;
chart1.Series[0].Points.AddXY(x, y);

if (y <= 0)
{
    timer1.Stop();
}