← Simulation & Statistics

Simulation & Statistics · Part 3 of 12

Flight with atmosphere

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

Model with drag: dvx/dt = −(β/m) vx √(vx² + vy²), dvy/dt = −g − (β/m) vy √(vx² + vy²), with β = 0.5·C·S·ρ, C ≈ 0.15, ρ = 1.29

First we have to solve the model and that's what will be implemented in the program.

Step-by-step update with k = β/m: vx and vy lose k·v·√(vx² + vy²)·Δt (vy also loses g·Δt), then x += vx·Δt and y += vy·Δt

Result

The flight window before launch: inputs for height, angle, speed, size and weight, all zero, and an empty chart

A launch at 45° and 30 m/s with drag: the arc peaks near 16 m and lands short and steep, about 49 m away after 3.2 s

Implementation

First Model

C#
chart1.Series[0].Points.Clear();
flight = new Flight(inputHeight.Value, inputSpeed.Value, inputAngle.Value, inputSize.Value, inputWeight.Value);
chart1.Series[0].Points.AddXY(flight.X, flight.Y);
timer1.Start();

Model on each unit of time

C#
flight.NextStep();
label4.Text = "Time: " + flight.T;
label7.Text = "Distance: " + flight.X;
chart1.Series[0].Points.AddXY(flight.X, flight.Y);

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

Model

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Simulation_Lab3
{
    class Flight
    {
        decimal t, s;
        decimal x, y;
        decimal v, v0;

        decimal m, k;
        decimal vx, vy;
        decimal cosa, sina;
        const decimal C = 0.15M;
        const decimal g = 9.81M;
        const decimal dt = 0.1M;
        const decimal rho = 1.29M;

        public decimal T { get { return t; } }
        public decimal X { get { return x; } }
        public decimal Y { get { return y; } }

        public Flight(decimal inputHeight, decimal inputSpeed, decimal inputAngle, decimal inputSize, decimal inputWeight)
        {
            t = 0;
            x = 0;

            y = inputHeight;
            v0 = inputSpeed;

            double a = (double) inputAngle * Math.PI / 180;
            cosa = (decimal) Math.Cos(a);
            sina = (decimal)Math.Sin(a);

            s = inputSize;
            m = inputWeight;

            k = 0.5M * C * rho * s / m;
            vx = v0 * cosa;
            vy = v0 * sina;
        }

        public void NextStep()
        {
            t += dt;

            v = (decimal) Math.Sqrt((double)(vx * vx + vy * vy));
            vx = vx - k * vx * v * dt;
            vy = vy - (g + k * vy * v) * dt;

            x = x + vx * dt;
            y = y + vy * dt;
        }
    }
}