Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static double pi = Math.Acos(-1);
- enum TargetType {
- AIRCRAFT,
- MISSLE
- };
- class TPoint
- {
- public double x, y;
- public TPoint(double x, double y) {
- this.x = x;
- this.y = y;
- }
- public double Dist(TPoint p)
- {
- return Math.Sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y));
- }
- }
- abstract class TPosObject
- {
- public TPoint InitPosition;
- public TPoint CurPosition;
- public double CurTime;
- public TPosObject(TPoint p) {
- InitPosition = p;
- CurPosition = p;
- CurTime = 0;
- }
- public abstract void Move(double t);
- }
- abstract class TTarget : TPosObject {
- public double v;
- public double alpha;
- public TargetType type;
- public TTarget(TPoint p, double v, double alpha, TargetType type) :
- base(p)
- {
- this.v = v;
- this.alpha = alpha;
- this.type = type;
- }
- };
- class TAirCraft : TTarget {
- public TAirCraft(TPoint p, double v, double alpha)
- : base(p, v, alpha, TargetType.AIRCRAFT)
- {
- }
- public override void Move(double t) {
- CurPosition = new TPoint(CurPosition.x - (t - CurTime) * v * Math.Cos(alpha),
- CurPosition.y - (t - CurTime) * v * Math.Sin(alpha));
- CurTime = t;
- }
- };
- class TMissle : TTarget {
- public double a;
- public TMissle(TPoint p, double v, double alpha, double a)
- : base(p, v, alpha, TargetType.MISSLE)
- {
- this.a = a;
- }
- public override void Move(double t) {
- CurPosition = new TPoint(CurPosition.x - (t - CurTime) * (v + a * (t - CurTime) / 2.0) * Math.Cos(alpha),
- CurPosition.y - (t - CurTime) * (v + a * (t - CurTime) / 2.0) * Math.Sin(alpha));
- CurTime = t;
- }
- };
- class TCommandPost : TPosObject {
- public double SafetyDistance;
- TCommandPost(TPoint p, double safetyDistance)
- : base(p)
- {
- this.SafetyDistance = safetyDistance;
- }
- public override void Move(double t) {
- CurTime = t;
- }
- };
- class TRLS : TPosObject{
- public double ScanDist;
- public double Distance;
- public double Peleng;
- public TRLS(TPoint T, double scanDist)
- : base(T)
- {
- ScanDist = scanDist;
- }
- public override void Move(double t) {
- CurTime = t;
- }
- public bool Measure(TTarget l, double t) {
- l.Move(t);
- Distance = l.CurPosition.Dist(CurPosition);
- Peleng = Math.Atan((CurPosition.x - l.CurPosition.x) / (CurPosition.y - l.CurPosition.y)) / pi * 180;
- return Distance <= ScanDist;
- }
- };
- class TSimulator {
- public double T0, Tk;
- public double dt;
- public TRLS RLS;
- public TCommandPost CP;
- public List<TTarget> Targets;
- public StreamWriter MyFile;
- public int CountTarget;
- void CretatTarget(TargetType type, params double[] par)
- {
- if (type == TargetType.AIRCRAFT)
- {
- Targets.Add(new TAirCraft(new TPoint(par[0], par[1]), par[2], par[3]));
- }
- else
- {
- Targets.Add(new TMissle(new TPoint(par[0], par[1]), par[2], par[3], par[4]));
- }
- }
- void Run() {
- foreach (TTarget T in Targets)
- {
- double t = T0;
- while (t < Tk) {
- if (RLS.Measure(T, t))
- {
- MyFile.Write(RLS.Distance);
- MyFile.Write(" ");
- MyFile.Write(RLS.Peleng);
- }
- }
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement