Esempio n. 1
0
        public static FsLatLonQuadrilateral ForRunway(FsLatLonPoint ThresholdCentre, double HeadingTrue, double WidthInFeet, double LengthInFeet)
        {
            double        num             = Math.PI * HeadingTrue / 180.0;
            double        decimalDegrees1 = FsLatitudeSpan.FromFeet(Math.Sin(num) * WidthInFeet / 2.0).DecimalDegrees;
            FsLatitude    fsLatitude1     = new FsLatitude(ThresholdCentre.Latitude.DecimalDegrees - decimalDegrees1);
            double        Feet            = Math.Cos(num) * WidthInFeet / 2.0;
            double        decimalDegrees2 = FsLongitudeSpan.FromFeet(Feet, fsLatitude1).DecimalDegrees;
            FsLongitude   Longitude1      = new FsLongitude(ThresholdCentre.Longitude.DecimalDegrees + decimalDegrees2);
            FsLatLonPoint P1 = new FsLatLonPoint(fsLatitude1, Longitude1);

            fsLatitude1 = new FsLatitude(ThresholdCentre.Latitude.DecimalDegrees + decimalDegrees1);
            double decimalDegrees3 = FsLongitudeSpan.FromFeet(Feet, fsLatitude1).DecimalDegrees;

            Longitude1 = new FsLongitude(ThresholdCentre.Longitude.DecimalDegrees - decimalDegrees3);
            FsLatLonPoint P0 = new FsLatLonPoint(fsLatitude1, Longitude1);
            double        decimalDegrees4 = FsLatitudeSpan.FromFeet(Math.Cos(num) * LengthInFeet).DecimalDegrees;
            FsLatitude    fsLatitude2     = new FsLatitude(ThresholdCentre.Latitude.DecimalDegrees + decimalDegrees4);
            double        decimalDegrees5 = FsLongitudeSpan.FromFeet(Math.Sin(num) * LengthInFeet, fsLatitude2).DecimalDegrees;
            FsLongitude   Longitude2      = new FsLongitude(ThresholdCentre.Longitude.DecimalDegrees + decimalDegrees5);
            FsLatLonPoint fsLatLonPoint   = new FsLatLonPoint(fsLatitude2, Longitude2);

            fsLatitude1 = new FsLatitude(fsLatLonPoint.Latitude.DecimalDegrees - decimalDegrees1);
            double decimalDegrees6 = FsLongitudeSpan.FromFeet(Feet, fsLatitude1).DecimalDegrees;

            Longitude1 = new FsLongitude(fsLatLonPoint.Longitude.DecimalDegrees + decimalDegrees6);
            FsLatLonPoint P3 = new FsLatLonPoint(fsLatitude1, Longitude1);

            fsLatitude1 = new FsLatitude(fsLatLonPoint.Latitude.DecimalDegrees + decimalDegrees1);
            double decimalDegrees7 = FsLongitudeSpan.FromFeet(Feet, fsLatitude1).DecimalDegrees;

            Longitude1 = new FsLongitude(fsLatLonPoint.Longitude.DecimalDegrees - decimalDegrees7);
            FsLatLonPoint P2 = new FsLatLonPoint(fsLatitude1, Longitude1);

            return(new FsLatLonQuadrilateral(P0, P1, P2, P3));
        }
Esempio n. 2
0
        public double BearingTo(FsLatLonPoint Point)
        {
            double num1 = 0.0;
            double num2 = Math.Abs(new FsLatitudeSpan(this.lat.DecimalDegrees - Point.Latitude.DecimalDegrees).ToFeet());
            double num3 = Math.Abs((new FsLongitudeSpan(Point.Longitude.DecimalDegrees - this.lon.DecimalDegrees).ToFeet(this.lat) + new FsLongitudeSpan(Point.Longitude.DecimalDegrees - this.lon.DecimalDegrees).ToFeet(Point.lat)) / 2.0);

            if (num2 == 0.0)
            {
                num1 = this.lon.DecimalDegrees > Point.Longitude.DecimalDegrees ? 270.0 : 90.0;
            }
            else if (this.lat.DecimalDegrees < Point.Latitude.DecimalDegrees && this.lon.DecimalDegrees < Point.Longitude.DecimalDegrees)
            {
                num1 = Math.Atan(num3 / num2) * 180.0 / Math.PI;
            }
            else if (this.lat.DecimalDegrees > Point.Latitude.DecimalDegrees && this.lon.DecimalDegrees < Point.Longitude.DecimalDegrees)
            {
                num1 = Math.Atan(num2 / num3) * 180.0 / Math.PI + 90.0;
            }
            else if (this.lat.DecimalDegrees > Point.Latitude.DecimalDegrees && this.lon.DecimalDegrees > Point.Longitude.DecimalDegrees)
            {
                num1 = Math.Atan(num3 / num2) * 180.0 / Math.PI + 180.0;
            }
            else if (this.lat.DecimalDegrees < Point.Latitude.DecimalDegrees && this.lon.DecimalDegrees > Point.Longitude.DecimalDegrees)
            {
                num1 = Math.Atan(num2 / num3) * 180.0 / Math.PI + 270.0;
            }
            return(num1);
        }
Esempio n. 3
0
        public double DistanceFromInFeet(FsLatLonPoint Point)
        {
            FsLongitudeSpan fsLongitudeSpan = FsLongitudeSpan.BetweenTwoLongitudes(Point.Longitude, this.lon);
            double          num             = (fsLongitudeSpan.ToFeet(this.lat) + fsLongitudeSpan.ToFeet(Point.lat)) / 2.0;
            double          feet            = new FsLatitudeSpan(Point.Latitude.DecimalDegrees - this.lat.DecimalDegrees).ToFeet();

            return(Math.Sqrt(num * num + feet * feet));
        }
Esempio n. 4
0
        public FsLatLonPoint OffsetByNauticalMiles(double Bearing, double Distance)
        {
            double        NauticalMiles1 = Math.Sin(Math.PI * Bearing / 180.0) * Distance;
            double        NauticalMiles2 = Math.Cos(Math.PI * Bearing / 180.0) * Distance;
            FsLatLonPoint fsLatLonPoint  = new FsLatLonPoint();

            fsLatLonPoint.lat = this.lat.Add(FsLatitudeSpan.FromNauticalMiles(NauticalMiles2));
            fsLatLonPoint.lon = this.lon.Add(FsLongitudeSpan.FromNauticalMiles(NauticalMiles1, fsLatLonPoint.lat));
            return(fsLatLonPoint);
        }
Esempio n. 5
0
        public FsLatLonPoint OffsetByFeet(double Bearing, double Distance)
        {
            double        Feet1         = Math.Sin(Math.PI * Bearing / 180.0) * Distance;
            double        Feet2         = Math.Cos(Math.PI * Bearing / 180.0) * Distance;
            FsLatLonPoint fsLatLonPoint = new FsLatLonPoint();

            fsLatLonPoint.lat = this.lat.Add(FsLatitudeSpan.FromFeet(Feet2));
            fsLatLonPoint.lon = this.lon.Add(FsLongitudeSpan.FromFeet(Feet1, fsLatLonPoint.lat));
            return(fsLatLonPoint);
        }
Esempio n. 6
0
        public double BearingFrom(FsLatLonPoint Point)
        {
            double num = 180.0 + this.BearingTo(Point);

            if (num >= 360.0)
            {
                num -= 360.0;
            }
            if (num < 0.0)
            {
                num += 360.0;
            }
            return(num);
        }
Esempio n. 7
0
        public FsLatLonQuadrilateral(FsLatLonPoint P0, FsLatLonPoint P1, FsLatLonPoint P2, FsLatLonPoint P3)
        {
            List <FsLatLonPoint> fsLatLonPointList1 = new List <FsLatLonPoint>();
            List <FsLatLonPoint> fsLatLonPointList2 = new List <FsLatLonPoint>();

            fsLatLonPointList1.Add(P0);
            fsLatLonPointList1.Add(P1);
            fsLatLonPointList1.Add(P2);
            fsLatLonPointList1.Add(P3);
            for (int index1 = 0; index1 < 3; ++index1)
            {
                double num    = 0.0;
                int    index2 = 0;
                for (int index3 = 0; index3 < fsLatLonPointList1.Count; ++index3)
                {
                    if (fsLatLonPointList1[index3].Latitude.UDegrees > num)
                    {
                        num    = fsLatLonPointList1[index3].Latitude.UDegrees;
                        index2 = index3;
                    }
                }
                fsLatLonPointList2.Add(fsLatLonPointList1[index2]);
                fsLatLonPointList1.RemoveAt(index2);
            }
            fsLatLonPointList2.Add(fsLatLonPointList1[0]);
            if (fsLatLonPointList2[1].Longitude.UDegrees > fsLatLonPointList2[0].Longitude.UDegrees)
            {
                this.ne = fsLatLonPointList2[1];
                this.nw = fsLatLonPointList2[0];
            }
            else
            {
                this.ne = fsLatLonPointList2[0];
                this.nw = fsLatLonPointList2[1];
            }
            if (fsLatLonPointList2[3].Longitude.UDegrees > fsLatLonPointList2[2].Longitude.UDegrees)
            {
                this.se = fsLatLonPointList2[3];
                this.sw = fsLatLonPointList2[2];
            }
            else
            {
                this.se = fsLatLonPointList2[2];
                this.sw = fsLatLonPointList2[3];
            }
        }
Esempio n. 8
0
        internal void updateFromByteArrays(byte[] slot, byte[] slotExtra, long playerAlt, long playerLat, long playerLon, short playerMagVar)
        {
            this.lat = BitConverter.ToSingle(slot, 4);
            this.lon = BitConverter.ToSingle(slot, 8);
            this.alt = BitConverter.ToSingle(slot, 12);
            this.hdg = BitConverter.ToUInt16(slot, 16);
            this.gs  = BitConverter.ToInt16(slot, 18);
            this.vs  = BitConverter.ToInt16(slot, 20);
            Encoding ascii = Encoding.ASCII;
            string   str   = ascii.GetString(slot, 22, 15);

            this.idATC = str.Substring(0, str.IndexOf(char.MinValue));
            this.state = slot[37];
            this.com1  = BitConverter.ToInt16(slot, 38);
            if (FSUIPCConnection.FlightSimVersionConnected == FlightSim.FSX)
            {
                this.gateName   = slotExtra[0];
                this.gateType   = slotExtra[1];
                this.gateNumber = BitConverter.ToInt16(slotExtra, 2);
            }
            else
            {
                this.key  = BitConverter.ToInt32(slotExtra, 0);
                this.file = BitConverter.ToInt16(slotExtra, 4);
            }
            this.pitch           = BitConverter.ToInt16(slotExtra, 6);
            this.departureICAO   = ascii.GetString(slotExtra, 8, 4);
            this.destinationICAO = ascii.GetString(slotExtra, 12, 4);
            this.runway          = new FSRunway()
            {
                Number     = slotExtra[16],
                Designator = (FSRunwayDesignator)slotExtra[17]
            };
            this.bank    = BitConverter.ToInt16(slotExtra, 18);
            this.altDiff = (double)this.alt - (double)playerAlt / 65536.0 / 65536.0 * 3.2808;
            FsLatLonPoint fsLatLonPoint = new FsLatLonPoint(new FsLatitude(playerLat), new FsLongitude(playerLon));
            FsLatLonPoint Point         = new FsLatLonPoint(new FsLatitude((double)this.lat), new FsLongitude((double)this.lon));

            this.distance  = fsLatLonPoint.DistanceFromInFeet(Point);
            this.bearingTo = fsLatLonPoint.BearingTo(Point);
            this.magVar    = (double)playerMagVar * 360.0 / 65536.0;
        }
Esempio n. 9
0
        public bool ContainsPoint(FsLatLonPoint point)
        {
            bool   flag       = false;
            double udegrees1  = this.nw.Latitude.UDegrees;
            double udegrees2  = this.sw.Latitude.UDegrees;
            double udegrees3  = this.se.Latitude.UDegrees;
            double udegrees4  = this.ne.Latitude.UDegrees;
            double udegrees5  = this.nw.Longitude.UDegrees;
            double udegrees6  = this.sw.Longitude.UDegrees;
            double udegrees7  = this.se.Longitude.UDegrees;
            double udegrees8  = this.ne.Longitude.UDegrees;
            double udegrees9  = point.Longitude.UDegrees;
            double udegrees10 = point.Latitude.UDegrees;

            if (udegrees9 > udegrees5 + (udegrees6 - udegrees5) / (udegrees1 - udegrees2) * (udegrees1 - udegrees10) && udegrees9 < udegrees8 + (udegrees7 - udegrees8) / (udegrees4 - udegrees3) * (udegrees4 - udegrees10) && udegrees10 > udegrees2 + (udegrees3 - udegrees2) / (udegrees7 - udegrees6) * (udegrees9 - udegrees6))
            {
                flag = udegrees10 < udegrees1 + (udegrees4 - udegrees1) / (udegrees8 - udegrees5) * (udegrees9 - udegrees5);
            }
            return(flag);
        }
Esempio n. 10
0
 public double DistanceFromInMetres(FsLatLonPoint Point)
 {
     return(this.DistanceFromInFeet(Point) / 3.2808);
 }
Esempio n. 11
0
 public double DistanceFromInNauticalMiles(FsLatLonPoint Point)
 {
     return(this.DistanceFromInFeet(Point) / 6076.1155);
 }