Skip to content
Snippets Groups Projects
Commit 2cc75688 authored by KTKadyshev's avatar KTKadyshev
Browse files

Upload New File

parent 96b72716
No related branches found
No related tags found
No related merge requests found
#include "module.h"
#include <math.h>
#define _USE_MATH_DEFINES
# define M_PI 3.14159265358979323846
#include <iostream>
TAObject::TAObject(double x_, double y_) {
x = x_;
y = y_;
f = false;
}
TLA::TLA(double x_, double y_, double V_, double xc_, double yc_) : TAObject(x_, y_)
{
xc = xc_;
yc = yc_;
R = sqrt((x - xc) * (x - xc) + (y - yc) * (y - yc));
double b = 0;
if (x > xc)
b = 0;
else if (x < xc && y < yc)
b = -1;
else if (x < xc && y > yc)
b = +1;
fi = b * M_PI + atan2(y - yc, x - xc);
V = V_;
landing = false;
}
TAircraft::TAircraft(double x_, double y_, double V_, double xc_, double yc_) : TLA(x_, y_, V_, xc_, yc_)
{
}
void TAircraft::move(double t, int a)
{
double omega = -V / R;
x = -(xc + R * cos(fi + omega * t)) * (a - 1) + a * (x + V * DT);
y = -(yc + R * sin(fi + omega * t)) * (a - 1) + y * a;
}
int TAircraft::computeA(const TAirport& airport)
{
int a = 0;
double XL = airport.x + 1.1 * airport.l;
if (!(airport.f && !f) && (x < XL) && (fabs(y - airport.y) < (airport.l / 50.0)))
a = 1;
else
a = 0;
return a;
}
bool TAircraft::computeLanding(const TAirport& airport)
{
if ((x > (airport.x + airport.l)) && f)
landing = true;
else {
landing = false;
f = true;
}
return landing;
}
THelicopter::THelicopter(double x_, double y_, double V_, double xc_, double yc_) : TLA(x_, y_, V_, xc_, yc_)
{
}
void THelicopter::move(double t, int a)
{
x = x - a * V * cos(fi) * DT;
y = y - a * V * sin(fi) * DT;
}
int THelicopter::computeA(const TAirport& airport)
{
int a = 0;
if (!(airport.f && !f))
a = 1;
else
a = 0;
return a;
}
bool THelicopter::computeLanding(const TAirport& airport)
{
if ( (((x - airport.x)* (x - airport.x) + (y - airport.y)* (y - airport.y)) < (airport.l / 50)* (airport.l / 50)) && f)
landing = true;
else
landing = false;
return landing;
}
const int NN = 3;
TAirport::TAirport(double x_, double y_, double l_) : TAObject(x_, y_)
{
FILE* file = fopen("oop.txt", "wt+");
l = l_;
LA = new PLA[NN];
LA[0] = new TAircraft(-1000, -1500, 100, x_, y_);
LA[1] = new TAircraft(2000, 2500, -150, x_, y_);
LA[2] = new THelicopter(2000, 2000, -10, x_, y_);
fclose(file);
};
TAirport::~TAirport()
{
PLA la = LA[0];
for (int i = 0; i < NN; i++) {
if(LA[i] != NULL)
delete LA[i];
}
delete[] LA;
}
void TAirport::Do(double t0, double tk)
{
int N = 0;
FILE* file = fopen("oop.txt", "wt+");
double last_t = -1000;
for (double t = t0; t < tk; t = t + DT)
{
bool shouldOutput = (t - last_t) >= 60;
for (int i = 0; i < NN; i++)
{
PLA la = LA[i];
if (shouldOutput)
{
last_t = t;
fprintf(file, "%f, %d, %f,%f, %d\r\n", t, (i + 1), la->x, la->y, la->f);
}
if (!la->f) {
int a = la->computeA(*this);
la->move(t, a);
if (la->computeLanding(*this))
{
f = true;
la->f = true; // landed
N++;
}
else
f = false;
}
}
}
fclose(file);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment