Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.65 KB | None | 0 0
  1. static double pi = Math.Acos(-1);
  2.         enum TargetType {
  3.             AIRCRAFT,
  4.             MISSLE
  5.         };
  6.  
  7.         class TPoint
  8.         {
  9.             public double x, y;
  10.  
  11.             public TPoint(double x, double y) {
  12.                 this.x = x;
  13.                 this.y = y;
  14.             }
  15.  
  16.             public double Dist(TPoint p)
  17.             {
  18.                 return Math.Sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y));
  19.             }
  20.         }
  21.  
  22.         abstract class TPosObject
  23.         {
  24.             public TPoint InitPosition;
  25.             public TPoint CurPosition;
  26.             public double CurTime;
  27.  
  28.             public TPosObject(TPoint p) {
  29.                 InitPosition = p;
  30.                 CurPosition = p;
  31.                 CurTime = 0;
  32.             }
  33.  
  34.             public abstract void Move(double t);
  35.         }
  36.        
  37.         abstract class TTarget : TPosObject {
  38.             public double v;
  39.             public double alpha;
  40.             public TargetType type;
  41.            
  42.             public TTarget(TPoint  p, double v, double alpha, TargetType type) :
  43.                 base(p)
  44.             {
  45.                
  46.                 this.v = v;
  47.                 this.alpha = alpha;
  48.                 this.type = type;
  49.             }
  50.         };
  51.        
  52.         class TAirCraft : TTarget {
  53.             public TAirCraft(TPoint p, double v, double alpha)
  54.                 : base(p, v, alpha, TargetType.AIRCRAFT)
  55.             {
  56.             }
  57.             public override void Move(double t) {
  58.                 CurPosition = new TPoint(CurPosition.x - (t - CurTime) * v * Math.Cos(alpha),
  59.                                          CurPosition.y - (t - CurTime) * v * Math.Sin(alpha));
  60.                 CurTime = t;
  61.             }  
  62.         };
  63.        
  64.         class TMissle : TTarget {
  65.             public double a;
  66.             public TMissle(TPoint p, double v, double alpha, double a)
  67.                 : base(p, v, alpha, TargetType.MISSLE)
  68.             {
  69.                 this.a = a;
  70.             }
  71.             public override void Move(double t) {
  72.                 CurPosition = new TPoint(CurPosition.x - (t - CurTime) * (v + a * (t - CurTime) / 2.0) * Math.Cos(alpha),
  73.                                          CurPosition.y - (t - CurTime) * (v + a * (t - CurTime) / 2.0) * Math.Sin(alpha));
  74.  
  75.                 CurTime = t;
  76.             }  
  77.         };
  78.  
  79.         class TCommandPost : TPosObject {
  80.             public double SafetyDistance;
  81.  
  82.             TCommandPost(TPoint p, double safetyDistance)
  83.                 : base(p)
  84.             {
  85.                 this.SafetyDistance = safetyDistance;
  86.             }
  87.             public override void Move(double t) {
  88.                 CurTime = t;
  89.             }
  90.         };
  91.        
  92.         class TRLS : TPosObject{
  93.             public double ScanDist;
  94.             public double Distance;
  95.             public double Peleng;
  96.             public TRLS(TPoint T, double scanDist)
  97.                 : base(T)
  98.             {
  99.                 ScanDist = scanDist;
  100.             }
  101.  
  102.             public override void Move(double t) {
  103.                 CurTime = t;
  104.             }
  105.  
  106.             public bool Measure(TTarget l, double t) {
  107.                 l.Move(t);
  108.                 Distance = l.CurPosition.Dist(CurPosition);
  109.                 Peleng = Math.Atan((CurPosition.x - l.CurPosition.x) / (CurPosition.y - l.CurPosition.y)) / pi * 180;
  110.                 return Distance <= ScanDist;
  111.             }
  112.         };
  113.  
  114.         class TSimulator {
  115.             public double T0, Tk;
  116.             public double dt;
  117.             public TRLS RLS;
  118.             public TCommandPost CP;
  119.             public List<TTarget> Targets;
  120.             public StreamWriter MyFile;
  121.             public int CountTarget;
  122.  
  123.             void CretatTarget(TargetType type, params double[] par)
  124.             {
  125.                 if (type == TargetType.AIRCRAFT)
  126.                 {
  127.                     Targets.Add(new TAirCraft(new TPoint(par[0], par[1]), par[2], par[3]));
  128.                 }
  129.                 else
  130.                 {
  131.                     Targets.Add(new TMissle(new TPoint(par[0], par[1]), par[2], par[3], par[4]));
  132.                 }
  133.             }
  134.  
  135.             void Run() {
  136.                 foreach (TTarget T in Targets)
  137.                 {
  138.                     double t = T0;
  139.                     while (t < Tk) {
  140.                         if (RLS.Measure(T, t))
  141.                         {
  142.                             MyFile.Write(RLS.Distance);
  143.                             MyFile.Write(" ");
  144.                             MyFile.Write(RLS.Peleng);  
  145.                         }
  146.                     }
  147.                 }
  148.             }
  149.         };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement