Beispiel #1
0
        public void StartAngle_CaarTest_Changing()
        {
            var centerVertex = new Vertex(1.0, 1.25);
            var startAngle   = GeoMath.DegToRad(36.8699);
            var endAngle     = GeoMath.DegToRad(143.1301);
            var radius       = 1.25;
            var testArc      = new GeoArc(centerVertex, startAngle, endAngle, radius);

            testArc.StartAngle = GeoMath.DegToRad(50);
            Assert.IsTrue(Math.Abs(testArc.Vertex0.X - 1.8035) < GeoMath.Tolerance);
            Assert.IsTrue(Math.Abs(testArc.Vertex0.Y - 2.2076) < GeoMath.Tolerance);
        }
Beispiel #2
0
        /// <summary>
        /// Add a number to the accumulator.
        /// </summary>
        /// <param name="y">Set <i>sum</i> += <i>y</i>.</param>
        public void Add(double y)
        {
            // Here's Shewchuk's solution...
            double u;                       // hold exact sum as [s, t, u]

            // Accumulate starting at least significant end
            {
                Pair r = GeoMath.sum(y, _t);
                y = r.First;
                u = r.Second;
            }
            {
                Pair r = GeoMath.sum(y, _s);
                _s = r.First;
                _t = r.Second;
            }
            // Start is _s, _t decreasing and non-adjacent.  Sum is now (s + t + u)
            // exactly with s, t, u non-adjacent and in decreasing order (except for
            // possible zeros).  The following code tries to normalize the result.
            // Ideally, we want _s = round(s+t+u) and _u = round(s+t+u - _s).  The
            // following does an approximate job (and maintains the decreasing
            // non-adjacent property).  Here are two "failures" using 3-bit floats:
            //
            // Case 1: _s is not equal to round(s+t+u) -- off by 1 ulp
            // [12, -1] - 8 -> [4, 0, -1] -> [4, -1] = 3 should be [3, 0] = 3
            //
            // Case 2: _s+_t is not as close to s+t+u as it shold be
            // [64, 5] + 4 -> [64, 8, 1] -> [64,  8] = 72 (off by 1)
            //                    should be [80, -7] = 73 (exact)
            //
            // "Fixing" these problems is probably not worth the expense.  The
            // representation inevitably leads to small errors in the accumulated
            // values.  The additional errors illustrated here amount to 1 ulp of the
            // less significant word during each addition to the Accumulator and an
            // additional possible error of 1 ulp in the reported sum.
            //
            // Incidentally, the "ideal" representation described above is not
            // canonical, because _s = round(_s + _t) may not be true.  For example,
            // with 3-bit floats:
            //
            // [128, 16] + 1 -> [160, -16] -- 160 = round(145).
            // But [160, 0] - 16 -> [128, 16] -- 128 = round(144).
            //
            if (_s == 0)              // This implies t == 0,
            {
                _s = u;               // so result is u
            }
            else
            {
                _t += u;                // otherwise just accumulate u to t.
            }
        }
Beispiel #3
0
        /// <summary>
        /// 由地心地固空间直角坐标计算大地坐标。
        /// </summary>
        /// <param name="pos">空间直角坐标</param>
        /// <param name="date">儒略日</param>
        /// <param name="ellipsoid">参考椭球</param>
        /// <param name="unit">角度单位</param>
        /// <returns></returns>
        public static GeoCoord XyzToGeoCoord(IXYZ pos, Julian date, Geo.Referencing.Ellipsoid ellipsoid = null, AngleUnit unit = AngleUnit.Degree)
        {
            if (ellipsoid == null)
            {
                ellipsoid = Geo.Referencing.Ellipsoid.WGS84;
            }
            double f = ellipsoid.Flattening;
            double a = ellipsoid.SemiMajorAxis;

            double TwoPi = 2 * CoordConsts.PI;
            double x     = pos.X;
            double y     = pos.Y;
            double z     = pos.Z;

            double theta = (GeoMath.AcTan(pos.Y, pos.X) - date.GetGreenwichMeanSiderealTime()) % TwoPi;

            theta = theta % TwoPi;

            if (theta < 0.0)
            {
                // "wrap" negative modulo
                theta += TwoPi;
            }

            double r   = Math.Sqrt(x * x + y * y);
            double e2  = f * (2.0 - f);
            double lat = GeoMath.AcTan(z, r);

            const double DELTA = 1.0e-07;
            double       phi;
            double       c;

            do
            {
                phi = lat;
                c   = 1.0 / Math.Sqrt(1.0 - e2 * GeoMath.Sqr(Sin(phi)));
                lat = GeoMath.AcTan(pos.Z + a * c * e2 * Sin(phi), r);
            }while (Math.Abs(lat - phi) > DELTA);

            double Altitude = (r / Cos(lat)) - a * c;

            if (unit == AngleUnit.Degree)
            {
                lat   *= AngularConvert.RadToDegMultiplier;
                theta *= AngularConvert.RadToDegMultiplier;
            }

            double Lat = lat;
            double Lon = theta;

            return(new GeoCoord(Lon, Lat, Altitude, unit));
        }
Beispiel #4
0
        public void TestAngleBetweenAzimuths_positive()
        {
            double angle1 = GeoMath.AngleBetweenAzimuths(270, 30);
            double angle2 = GeoMath.AngleBetweenAzimuths(170, 10);

            Assert.AreEqual(angle1, 120);
            Assert.AreEqual(angle2, 160);

            angle1 = GeoMath.AllAngleBetweenAzimuths(270, 30);
            angle2 = GeoMath.AllAngleBetweenAzimuths(170, 10);
            Assert.AreEqual(angle1, -120);
            Assert.AreEqual(angle2, 160);
        }
Beispiel #5
0
        public void Magnitude_InputOneVector_ReturnItsLength()
        {
            var input = new BasicGeoposition()
            {
                Latitude = 1, Longitude = 1, Altitude = 1
            };
            var    result = GeoMath.Magnitude(input);
            double expect = 1.73205;

            Assert.AreEqual(expect, result, 0.00001, $@"Wrong magnitude returned.
                                                        Expected: {expect},
                                                        Actual: {result}");
        }
Beispiel #6
0
        public void Normalize_InputLatitude5_ReturnLatitude1()
        {
            var input = new BasicGeoposition()
            {
                Latitude = 1
            };
            var    result = GeoMath.Normalize(input);
            double expect = 1;

            Assert.AreEqual(expect, result.Latitude, 0.00001, $@"Wrong normalization in latitude.
                                                        Expected: {expect},
                                                        Actual: {result.Latitude}");
        }
Beispiel #7
0
        public void TestAngleBetweenAzimuths_large()
        {
            double a1 = GeoMath.AngleBetweenAzimuths(720, 20);
            double a2 = GeoMath.AngleBetweenAzimuths(-10, 370);

            Assert.AreEqual(a1, 20);
            Assert.AreEqual(a2, 20);

            a1 = GeoMath.AllAngleBetweenAzimuths(720, 20);
            a2 = GeoMath.AllAngleBetweenAzimuths(-10, 370);
            Assert.AreEqual(a1, -20);
            Assert.AreEqual(a2, -20);
        }
Beispiel #8
0
        public void TestAngleBetweenAzimuths_negative()
        {
            double angle3 = GeoMath.AngleBetweenAzimuths(30, 270);
            double angle4 = GeoMath.AngleBetweenAzimuths(10, 170);

            Assert.AreEqual(angle3, 120);
            Assert.AreEqual(angle4, 160);

            angle3 = GeoMath.AllAngleBetweenAzimuths(30, 270);
            angle4 = GeoMath.AllAngleBetweenAzimuths(10, 170);
            Assert.AreEqual(angle3, 120);
            Assert.AreEqual(angle4, -160);
        }
Beispiel #9
0
      /// <summary>
      /// Standard constructor.
      /// </summary>
      /// <param name="tle">Two-line element orbital parameters.</param>
      public Orbit(TwoLineElement tle)
      {
         TwoLineElement     = tle;
         Epoch = TwoLineElement.EpochJulian;

         m_Inclination   = GetRad(TwoLineElement.Field.Inclination);
         m_Eccentricity  = TwoLineElement.GetField(TwoLineElement.Field.Eccentricity);
         m_RAAN          = GetRad(TwoLineElement.Field.Raan);              
         m_ArgPerigee    = GetRad(TwoLineElement.Field.ArgPerigee);        
         m_BStar         = TwoLineElement.GetField(TwoLineElement.Field.BStarDrag);   
         m_Drag          = TwoLineElement.GetField(TwoLineElement.Field.MeanMotionDt);
         m_MeanAnomaly   = GetRad(TwoLineElement.Field.MeanAnomaly);
         m_TleMeanMotion = TwoLineElement.GetField(TwoLineElement.Field.MeanMotion);  

         // Recover the original mean motion and semimajor axis from the
         // input elements.
         double mm     = TleMeanMotion;
         double rpmin  = mm * OrbitConsts.TwoPi / OrbitConsts.MinPerDay;   // rads per second

         double a1     = Math.Pow(OrbitConsts.Xke / rpmin, 2.0 / 3.0);
         double e      = Eccentricity;
         double i      = Inclination;
         double temp = (1.5 * OrbitConsts.Ck2 * (3.0 * GeoMath.Sqr(Math.Cos(i)) - 1.0) / 
                         Math.Pow(1.0 - e * e, 1.5));   
         double delta1 = temp / (a1 * a1);
         double a0     = a1 * 
                        (1.0 - delta1 * 
                        ((1.0 / 3.0) + delta1 * 
                        (1.0 + 134.0 / 81.0 * delta1)));

         double delta0 = temp / (a0 * a0);

         m_rmMeanMotionRec    = rpmin / (1.0 + delta0);
         m_aeAxisSemiMajorRec = a0 / (1.0 - delta0);
         m_aeAxisSemiMinorRec = m_aeAxisSemiMajorRec * Math.Sqrt(1.0 - (e * e));
         m_kmPerigeeRec       = OrbitConsts.RadiusOfEquator * (m_aeAxisSemiMajorRec * (1.0 - e) - OrbitConsts.Ae);
         m_kmApogeeRec        = OrbitConsts.RadiusOfEquator * (m_aeAxisSemiMajorRec * (1.0 + e) - OrbitConsts.Ae);

         //针对周期的不同,选择不同的模型。
         if (Period.TotalMinutes >= 225.0)
         {
            // SDP4 - period >= 225 minutes.
            NoradModel = new NoradSDP4(this);
         }
         else
         {
            // SGP4 - period < 225 minutes
            NoradModel = new NoradSGP4(this);
         }
      }
Beispiel #10
0
        public void Radius_CaarTest_Changing()
        {
            var centerVertex = new Vertex(1.0, 1.25);
            var startAngle   = GeoMath.DegToRad(36.8699);
            var endAngle     = GeoMath.DegToRad(143.1301);
            var radius       = 1.25;
            var testArc      = new GeoArc(centerVertex, startAngle, endAngle, radius);

            testArc.Radius = 2;
            Assert.IsTrue(Math.Abs(testArc.Vertex0.X - 2.6000) < GeoMath.Tolerance);
            Assert.IsTrue(Math.Abs(testArc.Vertex0.Y - 2.4500) < GeoMath.Tolerance);
            Assert.IsTrue(Math.Abs(testArc.Vertex1.X - -0.6000) < GeoMath.Tolerance);
            Assert.IsTrue(Math.Abs(testArc.Vertex1.Y - 2.4500) < GeoMath.Tolerance);
        }
Beispiel #11
0
        public void IsInPolygonTest(double cX, double cY,
                                    double p1X, double p1Y, double p2X, double p2Y, double p3X, double p3Y,
                                    bool result)
        {
            var c        = new GeoPoint(cX, cY);
            var triangle = new List <GeoPoint>
            {
                new GeoPoint(p1X, p1Y),
                new GeoPoint(p2X, p2Y),
                new GeoPoint(p3X, p3Y)
            };

            Assert.AreEqual(GeoMath.IsInPolygon(c, triangle), result);
        }
Beispiel #12
0
    public void pairMap(GameObject user1, GameObject user2)
    {
        //Get the position and instanceIDs of two participants in a trigger, map their midpoint.
        //Shoot a ray straight down from midpoint to determine where the node grows from. spawn the node and set the id.

        var mid = GeoMath.midpoint(user1.transform.position, user2.transform.position);

        //we'll always get pairs of trigger events, so throw out every other one.
        if (!Spots.Contains(mid))
        {
            Spots.Add(mid);
        }
        else
        {
            Spots.Clear();
            return;
        }

        var hit = new RaycastHit();
        int id;

        if (Physics.Raycast(mid, Vector3.down, out hit))
        {
            //if we aren't over the ground, something's up.
            if (hit.collider.gameObject.tag == "Moon")
            {
                var        rotation = Quaternion.Euler(0, Random.Range(0, 360), 0);
                GameObject go       = Instantiate(Node, GeoMath.below(hit.point), rotation) as GameObject;
                //go.transform.eulerAngles.y = Random.Range(0,360);
                //GameObject go = Instantiate(Node, hit.point, Quaternion.identity) as GameObject;

                id = go.GetInstanceID();
                Nodes.Add(id, go);

                go.GetComponent <KaveNode>().addUser(user1.GetInstanceID(), user1);
                go.GetComponent <KaveNode>().addUser(user2.GetInstanceID(), user2);

                //gotta be a better way to do this
                var u1coll = user1.GetComponent <CollisionMgmt>();
                var u2coll = user2.GetComponent <CollisionMgmt>();

                u1coll.Nodes.Add(id, go);
                u1coll.join();

                u2coll.Nodes.Add(id, go);
                u2coll.join();
            }
        }
    }
        /// <summary>
        /// Creates a new instance of MapPolylineItem class. Calculates incomplete data.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="path"></param>
        /// <param name="layer"></param>
        /// <param name="strokeColor"></param>
        /// <param name="width"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public static MapPolylineItem GetMapPolylineItem(string name, IReadOnlyList <BasicGeoposition> path,
                                                         MapLayerItem layer, Color strokeColor, double width,
                                                         int id = -1)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException("Name cannot be empty", nameof(name));
            }

            if (path is null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            if (layer is null)
            {
                throw new ArgumentNullException(nameof(layer));
            }

            List <BasicGeoposition> left  = new List <BasicGeoposition>();
            List <BasicGeoposition> right = new List <BasicGeoposition>();

            for (int i = 0; i < path.Count - 1; i++)
            {
                BasicGeoposition z = new BasicGeoposition()
                {
                    Altitude = 1
                };
                BasicGeoposition vec  = GeoMath.Difference(path[i + 1], path[i]);
                BasicGeoposition prod = GeoMath.CrossProduct(vec, z);
                BasicGeoposition norm = GeoMath.Normalize(prod);
                BasicGeoposition tim  = GeoMath.TimesScalar(norm, width);
                right.Add(GeoMath.Sum(path[i], tim));
                right.Add(GeoMath.Sum(path[i + 1], tim));
                BasicGeoposition neg = GeoMath.TimesScalar(tim, -1);
                left.Insert(0, GeoMath.Sum(path[i], neg));
                left.Insert(0, GeoMath.Sum(path[i + 1], neg));
            }

            left.InsertRange(left.Count, right);
            return(GetMapPolylineItem(id,
                                      name,
                                      width,
                                      GeoMath.PolylineLength(path),
                                      left,
                                      path,
                                      layer,
                                      strokeColor));
        }
Beispiel #14
0
        public IEnumerable <MrCompeteGridView> QueryCompeteGridViews(DateTime initialDate, string district,
                                                                     AlarmCategory?compete, IEnumerable <List <GeoPoint> > boundaries)
        {
            var stats =
                _repository.QueryDate(initialDate, (repository, beginDate, endDate) => repository.GetAllList(
                                          x =>
                                          x.StatDate >= beginDate && x.StatDate < endDate && x.District == district &&
                                          x.Frequency == -1 && x.Compete == compete)).Where(x =>
            {
                var fields = x.Coordinates.GetSplittedFields(';')[0].GetSplittedFields(',');
                var point  = new GeoPoint(fields[0].ConvertToDouble(0), fields[1].ConvertToDouble(0));
                return(boundaries.Aggregate(false, (current, boundary) => current || GeoMath.IsInPolygon(point, boundary)));
            });

            return(stats.MapTo <IEnumerable <MrCompeteGridView> >());
        }
Beispiel #15
0
        public void Vertex0AndVertex1_CaarTest()
        {
            var centerVertex = new Vertex(1.0, 1.25);
            var startAngle   = GeoMath.DegToRad(36.8699);
            var endAngle     = GeoMath.DegToRad(143.1301);
            var radius       = 1.25;
            var testArc      = new GeoArc(centerVertex, startAngle, endAngle, radius);

            // Starting Vertex
            Assert.IsTrue(Math.Abs(testArc.Vertex0.X - 2) < GeoMath.Tolerance);
            Assert.IsTrue(Math.Abs(testArc.Vertex0.Y - 2) < GeoMath.Tolerance);

            // Ending Vertex
            Assert.IsTrue(Math.Abs(testArc.Vertex1.X) < GeoMath.Tolerance);
            Assert.IsTrue(Math.Abs(testArc.Vertex1.Y - 2) < GeoMath.Tolerance);
        }
Beispiel #16
0
        /// <summary>
        /// 由测站地心地固大地坐标计算在天球空间直角坐标的位置和速度。
        /// </summary>
        /// <param name="geo">大地坐标</param>
        /// <param name="date">时间</param>
        /// <param name="ellipsoid">参考椭球</param>
        /// <param name="isKm">是否是千米</param>
        /// <returns></returns>
        public static MotionState GetMovingState(
            GeoCoord geo,
            Julian date,
            Geo.Referencing.Ellipsoid ellipsoid = null,
            bool isKm = true
            )
        {
            double lat = geo.Lat;
            double lon = geo.Lon;
            double alt = geo.Altitude;

            if (geo.Unit == AngleUnit.Degree)
            {
                lat = AngularConvert.DegToRad(lat);
                lon = AngularConvert.DegToRad(lon);
            }

            if (ellipsoid == null)
            {
                ellipsoid = Geo.Referencing.Ellipsoid.WGS84;
            }

            double f = ellipsoid.Flattening;
            double a = ellipsoid.SemiMajorAxis;

            if (isKm)
            {
                a = ellipsoid.SemiMajorAxis / 1000.0;
            }

            // Calculate Local Mean Sidereal Time (theta)
            double theta = date.GetLocalMeanSiderealTime(lon);

            double c     = 1.0 / Math.Sqrt(1.0 + f * (f - 2.0) * GeoMath.Sqr(Math.Sin(lat)));
            double s     = GeoMath.Sqr(1.0 - f) * c;
            double achcp = (a * c + alt) * Math.Cos(lat);

            XYZ pos = new XYZ();

            pos.X = achcp * Math.Cos(theta);
            pos.Y = achcp * Math.Sin(theta);
            pos.Z = (a * s + alt) * Math.Sin(lat);

            XYZ vel = GetVelocityInCelestialSphere(pos);

            return(new MotionState(pos, vel));
        }
        public static async Task DownloadFiles()
        {
            List <Task>        tasks = new List <Task>();
            LocalStorageHelper lsh   = new LocalStorageHelper();

            tasks.Add(lsh.DownloadFiles());

            Geolocator         locator = new Geolocator();
            Task <Geoposition> tpos    = locator.GetGeopositionAsync(TimeSpan.FromMinutes(5), TimeSpan.FromSeconds(10)).AsTask();

            foreach (var tile in await SecondaryTile.FindAllAsync())
            {
                int iCin = int.Parse(tile.TileId);
                PinnedCinemas.Add(iCin);
                tasks.Add(lsh.GetCinemaFilmListings(iCin));
            }

            foreach (int iCin in Config.FavCinemas)
            {
                if (PinnedCinemas.Contains(iCin))
                {
                    continue;
                }

                PinnedCinemas.Add(iCin);
                tasks.Add(lsh.GetCinemaFilmListings(iCin));
            }

            Geoposition pos = await tpos;

            IEnumerable <CinemaInfo> oc = App.Cinemas.Values.OrderBy(c => GeoMath.Distance(pos.Coordinate.Latitude, pos.Coordinate.Longitude, c.Latitude, c.Longitute, GeoMath.MeasureUnits.Miles)).Take(1);

            if (oc.Count() > 0)
            {
                int iCin = oc.First().ID;

                if (!PinnedCinemas.Contains(iCin))
                {
                    tasks.Add(lsh.GetCinemaFilmListings(iCin));
                }
            }

            Task.WaitAll(tasks.ToArray());
        }
Beispiel #18
0
        public void CrossProduct_InputTwoVectorsOfOnes_ReturnZeroVector()
        {
            var input = new BasicGeoposition()
            {
                Latitude = 1, Longitude = 1, Altitude = 1
            };
            var result = GeoMath.CrossProduct(input, input);
            var expect = new BasicGeoposition();

            Assert.AreEqual(expect.Latitude, result.Latitude, 0.000001, $@"Result latitude mismatch. 
                                                                Expected: {expect.Latitude},
                                                                Actual: {result.Latitude}");
            Assert.AreEqual(expect.Longitude, result.Longitude, 0.000001, $@"Result Longitude mismatch. 
                                                                Expected: {expect.Longitude},
                                                                Actual: {result.Longitude}");
            Assert.AreEqual(expect.Altitude, result.Altitude, 0.000001, $@"Result Altitude mismatch. 
                                                                Expected: {expect.Altitude},
                                                                Actual: {result.Altitude}");
        }
Beispiel #19
0
        public void GenericGeoPolylineTest_1Arc()
        {
            // Line 0
            var v0 = new Vertex(3.5, 0);
            var v1 = new Vertex(6, 0);
            var l0 = new GeoLine(v0, v1);

            Assert.IsTrue(Math.Abs(l0.Length - 2.5) < GeoMath.Tolerance);

            // Line 1
            var v2 = new Vertex(6, 2.5);
            var l1 = new GeoLine(v1, v2);

            Assert.IsTrue(Math.Abs(l1.Length - 2.5) < GeoMath.Tolerance);

            // Arc
            var          centerPoint = new Vertex(4.75, 1.75);
            var          startAngle  = GeoMath.DegToRad(30.964);
            var          endAngle    = GeoMath.DegToRad(149.036);
            const double radius      = 1.4577;
            var          arc0        = new GeoArc(centerPoint, startAngle, endAngle, radius);

            Assert.IsTrue(Math.Abs(arc0.Length - 3.0040) < GeoMath.Tolerance);

            // Line 2
            var v3 = new Vertex(3.5, 2.5);
            var l2 = new GeoLine(v3, v0);

            Assert.IsTrue(Math.Abs(l2.Length - 2.5) < GeoMath.Tolerance);

            // GeoPolyline
            var geoPolyline = new GeoPolyline(); // Initialized

            // Adding sections to the GeoPolyline
            geoPolyline.Add(l0);
            geoPolyline.Add(l1);
            geoPolyline.Add(arc0);
            geoPolyline.Add(l2);

            // Assert
            Assert.IsTrue(Math.Abs(geoPolyline.Length - 10.5040) < GeoMath.Tolerance);
            Assert.IsTrue(Math.Abs(geoPolyline.Area - 7.5021) < GeoMath.Tolerance);
        }
Beispiel #20
0
        private bool IsPointInFence(GeoPoint geoPoint, GeoFence geoFence)
        {
            if (!GeoMath.IsPointInRectangular(geoPoint, geoFence.NWPoint, geoFence.SEPoint))
            {
                return(false);
            }

            if (geoFence.Type == FenceType.CIRCLE && !GeoMath.IsPointInCircle(geoPoint, geoFence.Nodes[0], GeoMath.Distance(geoFence.Nodes[0].Latitude, geoFence.Nodes[0].Longitude, geoFence.Nodes[1].Latitude, geoFence.Nodes[1].Longitude)))
            {
                return(false);
            }

            if (geoFence.Type == FenceType.SHAPE && !GeoMath.IsPointInShape(geoPoint, geoFence.Nodes))
            {
                return(false);
            }

            return(true);
        }
Beispiel #21
0
    List <StreetLineIntersectionResult> GetIntersectWithStreetLineResults(Vector2 start, Vector2 end, List <StreetLine> options, StreetLine ignored)
    {
        List <StreetLineIntersectionResult> intersectionResults = new List <StreetLineIntersectionResult>();
        Vector2 intersection;

        for (int i = 0; i < options.Count; i++)
        {
            if (ignored != null && ignored == options[i])
            {
                continue;
            }
            if (GeoMath.LineSegmentsIntersect(start, end, options[i].A, options[i].B, out intersection))
            {
                intersectionResults.Add(new StreetLineIntersectionResult(options[i], intersection));
            }
        }

        intersectionResults.Sort((a, b) => (Vector2.SqrMagnitude(start - a.intersection) < Vector2.SqrMagnitude(start - b.intersection)) ? -1 : 1);
        return(intersectionResults);
    }
Beispiel #22
0
        public void UpdateCell(CinemaInfo cinema)
        {
            this.Cinema = cinema;

            if (Application.UserLocation != null)
            {
                var distance = GeoMath.Distance(Application.UserLocation.Coordinate.Latitude, Application.UserLocation.Coordinate.Longitude, cinema.Latitude, cinema.Longitute, GeoMath.MeasureUnits.Miles);

                this.Distance.Text = String.Format("{0:N2} miles", distance);
            }
            else
            {
            }
            this.CinemaTitle.Text = cinema.Name;
            //this.CinemaTitle.SizeToFit ();

            ContentView.Layer.CornerRadius       = 10f;
            ContentView.Layer.MasksToBounds      = true;
            ContentView.Layer.RasterizationScale = UIScreen.MainScreen.Scale;
            ContentView.Layer.Opaque             = true;
        }
Beispiel #23
0
 bool PotentialLineHasCorrectSeparation(Vector2 start, Vector2 end, List <StreetLine> comparisonBase)
 {
     for (int i = 0; i < comparisonBase.Count; i++)
     {
         //we only want to check separation with ines to which we are close to paralell or straight up paralell
         float dot = Vector2.Dot((end - start).normalized, (comparisonBase[i].A - comparisonBase[i].B).normalized);
         if (Mathf.Abs(dot) < 0.7f)
         {
             continue;
         }
         //we also don't want to check separation with lines from which we are continuuing from
         if (start == comparisonBase[i].A || end == comparisonBase[i].A || start == comparisonBase[i].B || end == comparisonBase[i].B)
         {
             continue;
         }
         if (GeoMath.ClosestDistBetweenLineSegments(start, end, comparisonBase[i].A, comparisonBase[i].B) < minSeparation)
         {
             return(false);
         }
     }
     return(true);
 }
Beispiel #24
0
        public void Sum_InputTwoVectorsOfOnes_ReturnVectorOfTwos()
        {
            var input = new BasicGeoposition()
            {
                Latitude = 1, Longitude = 1, Altitude = 1
            };
            var result = GeoMath.Sum(input, input);
            var expect = new BasicGeoposition()
            {
                Latitude = 2, Longitude = 2, Altitude = 2
            };

            Assert.AreEqual(expect.Latitude, result.Latitude, 0.000001, $@"Result latitude mismatch. 
                                                                Expected: {expect.Latitude},
                                                                Actual: {result.Latitude}");
            Assert.AreEqual(expect.Longitude, result.Longitude, 0.000001, $@"Result Longitude mismatch. 
                                                                Expected: {expect.Longitude},
                                                                Actual: {result.Longitude}");
            Assert.AreEqual(expect.Altitude, result.Altitude, 0.000001, $@"Result Altitude mismatch. 
                                                                Expected: {expect.Altitude},
                                                                Actual: {result.Altitude}");
        }
        private static async Task <bool> IsFlightDetected(this IVehicle vehicle, GeoPoint startLocation,
                                                          GeoPoint targetLocation, int attemptsCount, bool isWithoutAltitude, double precisionMet, Action <string> logger,
                                                          CancellationToken cancel)
        {
            logger = logger ?? (_ => { });

            var startDistance = isWithoutAltitude
                ? Math.Abs(GeoMath.Distance(targetLocation.SetAltitude(0), startLocation.SetAltitude(0)))
                : Math.Abs(GeoMath.Distance(targetLocation, startLocation));

            var isFlying = false;

            for (var i = 0; i < attemptsCount; i++)
            {
                if (cancel.IsCancellationRequested)
                {
                    break;
                }
                Logger.Debug($"Send command GoTo to vehicle. Attempt number {i + 1}", startLocation);
                logger($"Send command GoTo to vehicle . Attempt number {i + 1}. {startLocation}");
                await vehicle.GoToGlob(targetLocation, cancel).ConfigureAwait(false);

                await Task.Delay(FlightCheckFrequency, cancel).ConfigureAwait(false);

                var loc  = vehicle.GlobalPosition.Value;
                var dist = isWithoutAltitude
                    ? Math.Abs(GeoMath.Distance(targetLocation.SetAltitude(0), loc.SetAltitude(0)))
                    : Math.Abs(GeoMath.Distance(targetLocation, loc));

                if (startDistance - dist > FlightSignDistance || dist <= precisionMet)
                {
                    isFlying = true;
                    break;
                }
            }

            return(isFlying);
        }
Beispiel #26
0
        public void TimesScalar_InputVectorOfOnesAnd2_ReturnVectorOfTwos()
        {
            var input = new BasicGeoposition()
            {
                Latitude = 1, Longitude = 1, Altitude = 1
            };
            double inputScalar = 2;
            var    result      = GeoMath.TimesScalar(input, inputScalar);
            var    expect      = new BasicGeoposition()
            {
                Latitude = 2, Longitude = 2, Altitude = 2
            };

            Assert.AreEqual(expect.Latitude, result.Latitude, 0.000001, $@"Result latitude mismatch. 
                                                                Expected: {expect.Latitude},
                                                                Actual: {result.Latitude}");
            Assert.AreEqual(expect.Longitude, result.Longitude, 0.000001, $@"Result Longitude mismatch. 
                                                                Expected: {expect.Longitude},
                                                                Actual: {result.Longitude}");
            Assert.AreEqual(expect.Altitude, result.Altitude, 0.000001, $@"Result Altitude mismatch. 
                                                                Expected: {expect.Altitude},
                                                                Actual: {result.Altitude}");
        }
Beispiel #27
0
        public void PolygonBorderLength_InputSquareWithSideLengthTenDegrees_Return4435000()
        {
            var path = new List <BasicGeoposition>()
            {
                new BasicGeoposition(),
                new BasicGeoposition()
                {
                    Latitude = 10
                },
                new BasicGeoposition()
                {
                    Latitude = 10, Longitude = 10
                },
                new BasicGeoposition()
                {
                    Longitude = 10
                }
            };
            var    result = GeoMath.PolygonBorderLength(path);
            double expect = 4435000;

            Assert.AreEqual(expect, result, 4000, $@"Returned value mismatch.\nExpected: {expect},\nActual: {result}");
        }
Beispiel #28
0
        public void PolylineLength_InputLineLikeOpenBoxWithSideLength10Degrees_Return3339000()
        {
            var path = new List <BasicGeoposition>()
            {
                new BasicGeoposition()
                {
                    Latitude = 10
                },
                new BasicGeoposition(),
                new BasicGeoposition()
                {
                    Longitude = 10
                },
                new BasicGeoposition()
                {
                    Latitude = 10, Longitude = 10
                }
            };
            var    result = GeoMath.PolylineLength(path);
            double expect = 3339000;

            Assert.AreEqual(expect, result, 3000, $@"Returned value mismatch.\nExpected: {expect},\nActual: {result}");
        }
        public override Android.Views.View GetView(int position, Android.Views.View convertView, Android.Views.ViewGroup parent)
        {
            View itemView = convertView ?? LayoutInflater.From(_context).Inflate(Resource.Layout.NearestCinemaButton, parent, false);

            Button btn = itemView as Button;

            var cinema = this._cinemas [position];

            if (CineworldApplication.UserLocation != null)
            {
                double d = GeoMath.Distance(CineworldApplication.UserLocation.Latitude, CineworldApplication.UserLocation.Longitude, cinema.Latitude, cinema.Longitute, Config.Region == Config.RegionDef.UK ? GeoMath.MeasureUnits.Miles : GeoMath.MeasureUnits.Kilometers);
                btn.Text = String.Format("{0}\n{1:N1} {2}", cinema.Name, d, Config.Region == Config.RegionDef.UK ? "miles" : "kilometers");
            }
            else
            {
                btn.Text = cinema.Name;
            }

            btn.Tag = cinema.ID;
            //btn.Alpha = 0.7f;

            return(btn);
        }
Beispiel #30
0
        public void CounterClockWiseTest()
        {
            // This test creates a geoPolyline in a counter clockwise direction

            // some vertices
            // Note that Vertex1 is to the right of vertex0
            Vertex[] vertices =
            {
                new Vertex(7, 0),     // Vertex0
                new Vertex(9.5, 0),   // Vertex1
                new Vertex(9.5, 2.5), // Vertex2
                new Vertex(7, 2.5)    // Vertex3
            };

            GeoBase[] sections =
            {
                new GeoLine(vertices[0],        vertices[1]),
                new GeoLine(vertices[1],        vertices[2]),
                new GeoArc(
                    new Vertex(8.25,                   1.75),
                    GeoMath.DegToRad(30.9638),
                    GeoMath.DegToRad(149.0362),
                    1.4577),
                new GeoLine(vertices[3],        vertices[0])
            };

            var geoPolyline = new GeoPolyline();

            foreach (var section in sections)
            {
                geoPolyline.Add(section);
            }

            Assert.IsTrue(Math.Abs(geoPolyline.Length - 10.5040) < GeoMath.Tolerance);
            Assert.IsTrue(Math.Abs(geoPolyline.Area - 7.5021) < GeoMath.Tolerance);
        }