Commit c6c8e09a authored by ADBragin's avatar ADBragin
Browse files

Add new file

parent 016a0960
from enum import Enum
from abc import ABC, abstractmethod
from math import cos, sin, atan
import math
class TargetType(Enum):
Missile = 1
Aircraft = 2
class TTarget(ABC):
def __init__(self, x_0, y_0, v, phi, tar_type: TargetType, t, x, y):
self.x_0 = x_0
self.y_0 = y_0
self.v = v
self.angle = phi
self.type = tar_type
self.t = t
self.x = x
self.y = y
@abstractmethod
def move(self, ti):
pass
class TAitcraft(TTarget):
def __init__(self, x_0, y_0, v, phi, tar_type: TargetType, t, x, y):
super().__init__(x_0, y_0, v, phi, tar_type, t, x, y)
def move(self, ti):
x = self.x
y = self.y
self.x = self.x_0 - self.v * cos(self.angle) * (ti - self.t)
self.y = self.y_0 - self.v * sin(self.angle) * (ti - self.t)
self.x_0 = x
self.y_0 = y
self.t = ti
class TMissile(TTarget):
def __init__(self, x_0, y_0, v, phi, tar_type: TargetType, t, x, y, n):
super().__init__(x_0, y_0, v, phi, tar_type, t, x, y)
self.n = n
def move(self, ti):
x = self.x
y = self.y
self.x = self.x_0 - (self.v + self.n * (ti - self.t)) * cos(self.angle) * (ti - self.t)
self.y = self.y_0 - (self.v + self.n * (ti - self.t)) * sin(self.angle) * (ti - self.t)
self.x_0 = x
self.y_0 = y
self.t = ti
class Rls:
def __init__(self, x, y, r, targets: list[TTarget]):
self.x = x
self.y = y
self.r = r
self.targets = targets
def pelengation(self, t0, tk):
dt = 0.1
t = t0
with open("gfff.txt", "w") as f:
while t <= tk:
for target in self.targets:
target.move(t)
D = math.sqrt((target.x - self.x) ** 2 + (target.y - self.y) ** 2)
if D < self.r:
Az = atan((target.y - self.y) / (target.x - self.x))
f.write(f'D = {D}, Az = {Az}; Target is {target.type}\n')
t += dt
plane = TAitcraft(1, 1, 1, 0.1, TargetType.Aircraft, 0, 1, 1)
missile = TMissile(2, 2, 1, 0.05, TargetType.Missile, 0, 2, 2, 1)
rls = Rls(0, 0, 5, [plane, missile])
rls.pelengation(0, 5)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment