public static Vector InterceptionLine(Vector A, Vector vA, Vector LineB_A, Vector LineB_B)
 {
     try
     {
         Vector va     = vA;
         Vector vb     = Vector.Direction(LineB_A, LineB_B);
         double lambda = -(A.Y * vb.X - LineB_A.Y * vb.X - A.X * vb.Y + LineB_A.X * vb.Y) / (va.Y * vb.X - va.X * vb.Y);
         double sigma  = -(A.Y * va.X - LineB_A.Y * va.X - A.X * va.Y + LineB_A.X * va.Y) / (va.Y * vb.X - va.X * vb.Y);
         if (lambda == double.NaN || sigma == double.NaN || sigma > 1 || sigma < 0 || A.Z + lambda * va.Z != LineB_A.Z + sigma * vb.Z)
         {
             return(null);
         }
         Vector result = A + (va * lambda);
         return(result);
     }
     catch { }
     return(null);
 }
Exemplo n.º 2
0
        public ParcourChannel(Vector Start, Vector End)
        {
            this.Start = Start;
            this.End   = End;
            Vector StartEnd = Vector.Direction(Start, End);

            for (int i = 0; i < 10; i++)
            {
                Vector linComb = Start + (StartEnd * (i / 9.0));
                LinearCombinations.Add(linComb);
            }
            double dist         = getDistance();
            double straightDist = getDistanceStraight();

            if (dist - straightDist > 0.1)
            {
                System.Console.Out.WriteLine("ERROR");
            }
        }
        public void GenerateParcour(ParcourSet parcour, Converter c, double lenght, double channel, int count)
        {
            this.parcour = parcour;
            this.c       = c;
            this.count   = count;
            Line Start = parcour.Line.Single(p => p.Type == (int)LineType.START) as Line;

            if (Start == null)
            {
                return;
            }
            #region StartVektoren
            Vector StartAV             = new Vector(c.LongitudeToX(Start.A.longitude), c.LatitudeToY(Start.A.latitude), 0);
            Vector StartBV             = new Vector(c.LongitudeToX(Start.B.longitude), c.LatitudeToY(Start.B.latitude), 0);
            Vector StartOV             = new Vector(c.LongitudeToX(Start.O.longitude), c.LatitudeToY(Start.O.latitude), 0);
            Vector StartAB             = Vector.Direction(StartAV, StartBV);
            Vector StartMV             = Vector.Middle(StartAV, StartBV);
            Vector StartLotOrientation = Vector.MinDistance(StartAV, StartBV, StartOV);

            double GateRadiusKm      = Converter.NMtoM(0.3);
            Vector StartABNormalized = StartAB / Vector.Abs(StartAB);
            double StartABLength     = Converter.Distance(c.XtoLongitude(StartAV.X), c.YtoLatitude(StartAV.Y), c.XtoLongitude((StartAV + StartABNormalized).X), c.YtoLatitude((StartAV + StartABNormalized).Y));
            Vector StartAB1KM        = StartABNormalized / StartABLength;

            StartLotOrientation = StartLotOrientation * (Vector.Abs(StartAB1KM * GateRadiusKm) / Vector.Abs(StartLotOrientation));
            StartOV             = StartMV + (StartLotOrientation * 2);

            Vector Start_A_M = StartAV + (StartAB1KM * GateRadiusKm);
            Vector Start_A_A = StartAV;
            Vector Start_A_B = Start_A_M + (StartAB1KM * GateRadiusKm);
            Vector Start_A_O = Start_A_M + StartLotOrientation;

            Line Start_A;
            if (parcour.Line.Any(p => p.Type == (int)LineType.START_A))
            {
                Start_A = parcour.Line.Single(p => p.Type == (int)LineType.START_A);
            }
            else
            {
                Start_A      = new Line();
                Start_A.Type = (int)LineType.START_A;
                parcour.Line.Add(Start_A);
            }
            Start_A.A = Factory.newGPSPoint(c.XtoLongitude(Start_A_A.X), c.YtoLatitude(Start_A_A.Y), 0);
            Start_A.B = Factory.newGPSPoint(c.XtoLongitude(Start_A_B.X), c.YtoLatitude(Start_A_B.Y), 0);
            Start_A.O = Factory.newGPSPoint(c.XtoLongitude(Start_A_O.X), c.YtoLatitude(Start_A_O.Y), 0);

            Vector Start_D_M = StartBV - (StartAB1KM * GateRadiusKm);
            Vector Start_D_B = StartBV;
            Vector Start_D_A = Start_D_M - (StartAB1KM * GateRadiusKm);
            Vector Start_D_O = Start_D_M + StartLotOrientation;
            Line   Start_D;
            if (parcour.Line.Any(p => p.Type == (int)LineType.START_D))
            {
                Start_D = parcour.Line.Single(p => p.Type == (int)LineType.START_D);
            }
            else
            {
                Start_D      = new Line();
                Start_D.Type = (int)LineType.START_D;
                parcour.Line.Add(Start_D);
            }
            Start_D.A = Factory.newGPSPoint(c.XtoLongitude(Start_D_A.X), c.YtoLatitude(Start_D_A.Y), 0);
            Start_D.B = Factory.newGPSPoint(c.XtoLongitude(Start_D_B.X), c.YtoLatitude(Start_D_B.Y), 0);
            Start_D.O = Factory.newGPSPoint(c.XtoLongitude(Start_D_O.X), c.YtoLatitude(Start_D_O.Y), 0);


            Vector Start_B_M = Start_A_M + (Vector.Direction(Start_A_M, Start_D_M) / 3.0);
            Vector Start_B_A = Start_B_M - (StartAB1KM * GateRadiusKm);
            Vector Start_B_B = Start_B_M + (StartAB1KM * GateRadiusKm);
            Vector Start_B_O = Start_B_M + StartLotOrientation;

            Line Start_B;
            if (parcour.Line.Any(p => p.Type == (int)LineType.START_B))
            {
                Start_B = parcour.Line.Single(p => p.Type == (int)LineType.START_B);
            }
            else
            {
                Start_B      = new Line();
                Start_B.Type = (int)LineType.START_B;
                parcour.Line.Add(Start_B);
            }
            Start_B.A = Factory.newGPSPoint(c.XtoLongitude(Start_B_A.X), c.YtoLatitude(Start_B_A.Y), 0);
            Start_B.B = Factory.newGPSPoint(c.XtoLongitude(Start_B_B.X), c.YtoLatitude(Start_B_B.Y), 0);
            Start_B.O = Factory.newGPSPoint(c.XtoLongitude(Start_B_O.X), c.YtoLatitude(Start_B_O.Y), 0);

            Vector Start_C_M = Start_A_M + ((Vector.Direction(Start_A_M, Start_D_M) * 2) / 3.0);
            Vector Start_C_B = Start_C_M - (StartAB1KM * GateRadiusKm);
            Vector Start_C_A = Start_C_M + (StartAB1KM * GateRadiusKm);
            Vector Start_C_O = Start_C_M + StartLotOrientation;
            Line   Start_C;
            if (parcour.Line.Any(p => p.Type == (int)LineType.START_C))
            {
                Start_C = parcour.Line.Single(p => p.Type == (int)LineType.START_C);
            }
            else
            {
                Start_C      = new Line();
                Start_C.Type = (int)LineType.START_C;
                parcour.Line.Add(Start_C);
            }
            Start_C.A = Factory.newGPSPoint(c.XtoLongitude(Start_C_A.X), c.YtoLatitude(Start_C_A.Y), 0);
            Start_C.B = Factory.newGPSPoint(c.XtoLongitude(Start_C_B.X), c.YtoLatitude(Start_C_B.Y), 0);
            Start_C.O = Factory.newGPSPoint(c.XtoLongitude(Start_C_O.X), c.YtoLatitude(Start_C_O.Y), 0);
            #endregion

            #region EndeVektoren
            double lengthKm  = Converter.NMtoM(lenght);
            Vector lotPoint  = StartMV + StartLotOrientation;
            double lotLenght = Converter.Distance(c.XtoLongitude(StartMV.X), c.YtoLatitude(StartMV.Y), c.XtoLongitude(lotPoint.X), c.YtoLatitude(lotPoint.Y));
            Vector StartEnd  = (StartLotOrientation / lotLenght) * lengthKm * EndLineDist; //Shorten to make linearcombinations of vectors ... factor to be definded

            Vector EndeAV = StartAV + StartEnd;
            Vector EndeBV = StartBV + StartEnd;
            Vector EndeMV = Vector.Middle(EndeAV, EndeBV);
            Vector EndeOV = EndeMV + StartLotOrientation;
            Vector EndeAB = Vector.Direction(EndeAV, EndeBV);

            Vector Ende_A_A = Start_A_A + StartEnd;
            Vector Ende_A_B = Start_A_B + StartEnd;
            Vector Ende_A_M = Start_A_M + StartEnd;
            Vector Ende_A_O = Start_A_O + StartEnd;

            Line END_A;
            if (parcour.Line.Any(p => p.Type == (int)LineType.END_A))
            {
                END_A = parcour.Line.Single(p => p.Type == (int)LineType.END_A);
            }
            else
            {
                END_A      = new Line();
                END_A.Type = (int)LineType.END_A;
                parcour.Line.Add(END_A);
            }
            END_A.A = Factory.newGPSPoint(c.XtoLongitude(Ende_A_A.X), c.YtoLatitude(Ende_A_A.Y), 0);
            END_A.B = Factory.newGPSPoint(c.XtoLongitude(Ende_A_B.X), c.YtoLatitude(Ende_A_B.Y), 0);
            END_A.O = Factory.newGPSPoint(c.XtoLongitude(Ende_A_O.X), c.YtoLatitude(Ende_A_O.Y), 0);

            Vector Ende_B_A = Start_B_A + StartEnd;
            Vector Ende_B_B = Start_B_B + StartEnd;
            Vector Ende_B_M = Start_B_M + StartEnd;
            Vector Ende_B_O = Start_B_O + StartEnd;

            Line END_B;
            if (parcour.Line.Any(p => p.Type == (int)LineType.END_B))
            {
                END_B = parcour.Line.Single(p => p.Type == (int)LineType.END_B);
            }
            else
            {
                END_B      = new Line();
                END_B.Type = (int)LineType.END_B;
                parcour.Line.Add(END_B);
            }
            END_B.A = Factory.newGPSPoint(c.XtoLongitude(Ende_B_A.X), c.YtoLatitude(Ende_B_A.Y), 0);
            END_B.B = Factory.newGPSPoint(c.XtoLongitude(Ende_B_B.X), c.YtoLatitude(Ende_B_B.Y), 0);
            END_B.O = Factory.newGPSPoint(c.XtoLongitude(Ende_B_O.X), c.YtoLatitude(Ende_B_O.Y), 0);

            Vector Ende_C_A = Start_C_A + StartEnd;
            Vector Ende_C_B = Start_C_B + StartEnd;
            Vector Ende_C_M = Start_C_M + StartEnd;
            Vector Ende_C_O = Start_C_O + StartEnd;
            Line   END_C;
            if (parcour.Line.Any(p => p.Type == (int)LineType.END_C))
            {
                END_C = parcour.Line.Single(p => p.Type == (int)LineType.END_C);
            }
            else
            {
                END_C      = new Line();
                END_C.Type = (int)LineType.END_C;
                parcour.Line.Add(END_C);
            }
            END_C.A = Factory.newGPSPoint(c.XtoLongitude(Ende_C_A.X), c.YtoLatitude(Ende_C_A.Y), 0);
            END_C.B = Factory.newGPSPoint(c.XtoLongitude(Ende_C_B.X), c.YtoLatitude(Ende_C_B.Y), 0);
            END_C.O = Factory.newGPSPoint(c.XtoLongitude(Ende_C_O.X), c.YtoLatitude(Ende_C_O.Y), 0);

            Vector Ende_D_A = Start_D_A + StartEnd;
            Vector Ende_D_B = Start_D_B + StartEnd;
            Vector Ende_D_M = Start_D_M + StartEnd;
            Vector Ende_D_O = Start_D_O + StartEnd;
            Line   END_D;
            if (parcour.Line.Any(p => p.Type == (int)LineType.END_D))
            {
                END_D = parcour.Line.Single(p => p.Type == (int)LineType.END_D);
            }
            else
            {
                END_D      = new Line();
                END_D.Type = (int)LineType.END_D;
                parcour.Line.Add(END_D);
            }
            END_D.A = Factory.newGPSPoint(c.XtoLongitude(Ende_D_A.X), c.YtoLatitude(Ende_D_A.Y), 0);
            END_D.B = Factory.newGPSPoint(c.XtoLongitude(Ende_D_B.X), c.YtoLatitude(Ende_D_B.Y), 0);
            END_D.O = Factory.newGPSPoint(c.XtoLongitude(Ende_D_O.X), c.YtoLatitude(Ende_D_O.Y), 0);
            #endregion

            #region LineOfNoReturn
            double lengthLONRKm = Converter.NMtoM(LineOfNoReturnDist);
            Vector StartToLONR  = (StartLotOrientation / lotLenght) * ((lengthKm * EndLineDist) - lengthLONRKm);

            Vector LONR_A = StartAV + StartToLONR;
            Vector LONR_B = StartBV + StartToLONR;
            Vector LONR_O = StartOV + StartToLONR;
            Line   LONR;
            if (parcour.Line.Any(p => p.Type == (int)LineType.NOBACKTRACKLINE))
            {
                LONR = parcour.Line.Single(p => p.Type == (int)LineType.NOBACKTRACKLINE);
            }
            else
            {
                LONR      = new Line();
                LONR.Type = (int)LineType.NOBACKTRACKLINE;
                parcour.Line.Add(LONR);
            }
            LONR.A = Factory.newGPSPoint(c.XtoLongitude(LONR_A.X), c.YtoLatitude(LONR_A.Y), 0);
            LONR.B = Factory.newGPSPoint(c.XtoLongitude(LONR_B.X), c.YtoLatitude(LONR_B.Y), 0);
            LONR.O = Factory.newGPSPoint(c.XtoLongitude(LONR_O.X), c.YtoLatitude(LONR_O.Y), 0);
            #endregion
            CalculateParcour(parcour, c, channel);
        }