Commit de76b904 authored by SETaratukhina's avatar SETaratukhina
Browse files

Загрузить новый файл

parent cedc3d34
import math
import random as r
r.seed()
g = 9.81
fw = open('log.txt', 'w')
fa = open('log.txt', 'a')
class TTarget:
x0 = y0 = x = y = v = k = T0 = float
ttype = int
def __init__(self, fx, fy, fv, fk):
self.x0 = fx
self.x = self.x0
self.y0 = fy
self.y = self.y0
self.v = fv
self.k = fk
class TAircraft(TTarget):
def __init__(self, fx, fy, fv, fk):
super().__init__(fx, fy, fv, fk)
def Move(self, t):
self.x = self.x0 - self.v * math.cos(self.k) * g * g * (t - self.T0)
self.y = self.y0 - self.v * math.sin(self.k) * g * g * (t - self.T0)
class TMissle(TTarget):
N = float
def __init__(self, fx, fy, fv, fk, fN):
super().__init__(fx, fy, fv, fk)
self.N = fN
def Move(self, t):
self.x = self.x0 - (self.v + self.N * (t - self.T0)) * math.cos(self.k) * g * g * (t - self.T0)
self.y = self.y0 - (self.v + self.N * (t - self.T0)) * math.sin(self.k) * g * g * (t - self.T0)
class RLS:
x = y = R0 = float
Targets = []
def __init__(self, fx, fy, fR0):
self.x = fx
self.y = fy
self.R0 = fR0
self.Targets = []
def Peleng(self, ft0, ftk, fdt):
tk = ftk
t = ft0
dt = fdt
TTarget.T0 = t
MN = 0
AN = 0
while tk >= t:
t += dt
for Target in self.Targets:
if (isinstance(Target, TMissle)):
MN += 1
if (isinstance(Target, TAircraft)):
AN += 1
Target.Move(t)
D = math.sqrt((Target.x - self.x) * (Target.x - self.x) + (Target.y - self.y) * (Target.y - self.y))
if self.R0 >= D:
Az = math.atan((Target.y - self.y) / (Target.x - self.y))
if (isinstance(Target, TMissle)):
fa.write(f"{round(t * 10) / 10}; Missle #{MN}; D = {D}; Az = {Az}\n")
if (isinstance(Target, TAircraft)):
fa.write(f"{round(t * 10) / 10}; Aircraft #{AN}; D = {D}; Az = {Az}\n")
MN = 0
AN = 0
fa.close()
def main():
fw.write('Log File\n')
fw.close()
print("Enter your RLS x and y:")
rlsx = float(input())
rlsy = float(input())
print("Enter your RLS R:")
rlsr = float(input())
Rls = RLS(rlsx, rlsy, rlsr)
print("How many Aircrafts do you need?")
A = int(input())
print("How many Missles do you need?")
M = int(input())
for i in range(A):
Ar = TAircraft(r.random() * 1000, r.random() * 1000, r.random() * 50, r.random() * 6.28)
Rls.Targets.append(Ar)
for i in range(M):
Ms = TMissle(r.random() * 1000, r.random() * 1000, r.random() * 100, r.random() * 6.28, r.random() * 50)
Rls.Targets.append(Ms)
Rls.Peleng(0, 10, 0.1)
if __name__ == "__main__":
main()
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