Beispiel #1
0
        public Square square_at(Coordinate coordinate)
        {
            return contains_token_at(coordinate) ? (Square) 
                new PlayingSquare(_squares[coordinate.X, coordinate.Y]) :
                new EmptyPlayingSquare();

        }
 public Coordinate Reproject(Coordinate coordinate, ISpatialReference @from, ISpatialReference to)
 {
     double[] xy, z;
     ToDotSpatial(coordinate, out xy, out z);
     DotSpatial.Projections.Reproject.ReprojectPoints(xy, z, GetProjectionInfo(@from), GetProjectionInfo(to), 0, 1);
     return ToGeoAPI(xy, z);
 }
 /// <summary>
 /// Normalizes the vector <param name="v"></param>
 /// </summary>
 /// <param name="v">The normalized <paramref name="v"/></param>
 public static void Normalize(Coordinate v)
 {
     double absVal = Math.Sqrt(v.X * v.X + v.Y * v.Y + v.Z * v.Z);
     v.X /= absVal;
     v.Y /= absVal;
     v.Z /= absVal;
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="p"></param>
        /// <param name="ring"></param>
        /// <returns></returns>
        public static bool IsPointInRing(Coordinate p, Coordinate[] ring)
        {
            int i;		    // point index; i1 = i-1 mod n
            int crossings = 0;	// number of edge/ray crossings
            int nPts = ring.Length;

            /* For each line edge l = (i-1, i), see if it crosses ray from test point in positive x direction. */
            for (i = 1; i < nPts; i++)
            {
                int i1 = i - 1;		    // point index; i1 = i-1 mod n
                Coordinate p1 = ring[i];
                Coordinate p2 = ring[i1];
                double x1 = p1.X - p.X;
                double y1 = p1.Y - p.Y;
                double x2 = p2.X - p.X;
                double y2 = p2.Y - p.Y;

                if (((y1 > 0) && (y2 <= 0)) || ((y2 > 0) && (y1 <= 0)))
                {
                    /* e straddles x axis, so compute intersection. */
                    double xInt = (x1 * y2 - x2 * y1) / (y2 - y1);		    // x intersection of e with ray
                    /* crosses ray if strictly positive intersection. */
                    if (0.0 < xInt) crossings++;
                }
            }

            /* p is inside if an odd number of crossings. */
            return (crossings % 2) == 1;
        }
Beispiel #5
0
        public void Multipg()
        {
            Random rnd = new Random();
            Polygon[] pg = new Polygon[50];
            GeoAPI.Geometries.IPolygon[] pgcheck = new GeoAPI.Geometries.IPolygon[50];
            GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory gf = new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory();
            for (int i = 0; i < 50; i++)
            {
                Coordinate center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);
                Coordinate[] coord = new Coordinate[36];
                GeoAPI.Geometries.ICoordinate[] coordscheck = new GeoAPI.Geometries.ICoordinate[36];
                for (int ii = 0; ii < 36; ii++)
                {
                    coord[ii] = new Coordinate(center.X + Math.Cos((ii * 10) * Math.PI / 10), center.Y + (ii * 10) * Math.PI / 10);
                    double x = coord[ii].X;
                    double y = coord[ii].Y;
                    GisSharpBlog.NetTopologySuite.Geometries.Coordinate c = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(x, y);
                    coordscheck[ii] = c;
                }
                coord[35] = new Coordinate(coord[0].X, coord[0].Y);
                coordscheck[35] = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(coordscheck[0].X, coordscheck[0].Y);
                GeoAPI.Geometries.ILinearRing ring = gf.CreateLinearRing(coordscheck);
                pgcheck[i] = gf.CreatePolygon(ring, null);
                pg[i] = new Polygon(coord);

            }
            MultiPolygon mpg = new MultiPolygon(pg);
            GeoAPI.Geometries.IMultiPolygon mpgcheck = gf.CreateMultiPolygon(pgcheck);
            for (int ii = 0; ii < mpg.Coordinates.Count; ii++)
            {
                Assert.AreEqual(mpg.Coordinates[ii].X, mpgcheck.Coordinates[ii].X);
                Assert.AreEqual(mpg.Coordinates[ii].Y, mpgcheck.Coordinates[ii].Y);
            }
        }
Beispiel #6
0
 private static string PointInformation()
 {
     StringBuilder text = new StringBuilder();
     Window window = Window.GetWindowAtCursor();
     Coordinate pt = new Coordinate(CoordinateType.Absolute, new WindowEntity.Point() { X = Cursor.Position.X, Y = Cursor.Position.Y });
     Color color = Desktop.Primary.GetPixelColor(pt);
     if(window != null)
     {
         WindowEntity.Point rel = pt.ToRelative(window);
         StretchedPoint st = pt.ToStretched(window);
         text.Append("<b>Window</b>: ");
         text.AppendFormat("[{0}, {1}] ", window.Width, window.Height);
         text.AppendFormat("\"{0}\"", window.Title);
         text.AppendLine();
         text.Append("<br><b>Color</b>: ");
         text.AppendLine(color.ToString());
         text.Append("<br><b>Coordinate</b>: Absolute: ");
         text.AppendFormat("X = {0}, Y = {1}", pt.X, pt.Y);
         text.Append("; Relative: ");
         text.AppendFormat("X = {0}, Y = {1}", rel.X, rel.Y);
         text.Append("; Stretched: ");
         text.AppendFormat(CultureInfo.InvariantCulture, "X = {0}, Y = {1}", st.X, st.Y);
     }
     else
     {
         text.Append("<b>Color</b>: ");
         text.AppendLine(color.ToString());
         text.Append("<br><b>Coordinate</b>: Absolute: ");
         text.AppendFormat("{0}, {1}", pt.X, pt.Y);
     }
     return text.ToString();
 }
Beispiel #7
0
 /// <summary>
 /// Creates a new instance of a vector where the X, Y and Z terms are the same as the
 /// specified coordinate.
 /// </summary>
 /// <param name="coord">The ICoordinate to use</param>
 public Vector(Coordinate coord)
 {
     X = coord.X;
     Y = coord.Y;
     Z = coord.Z;
     RemoveNan();
 }
        private void TestWriteZMValuesShapeFile(bool testM)
        {
            var points = new Coordinate[3];
            points[0] = new Coordinate(0, 0);
            points[1] = new Coordinate(1, 0);
            points[2] = new Coordinate(1, 1);

            var csFactory = DotSpatialAffineCoordinateSequenceFactory.Instance;
            var sequence = csFactory.Create(3, Ordinates.XYZM);
            for (var i = 0; i < 3; i++)
            {
                sequence.SetOrdinate(i, Ordinate.X, points[i].X);
                sequence.SetOrdinate(i, Ordinate.Y, points[i].Y);
                sequence.SetOrdinate(i, Ordinate.Z, 1 + i);
                if (testM)
                    sequence.SetOrdinate(i, Ordinate.M, 11 + i);
            }
            var lineString = Factory.CreateLineString(sequence);

            var attributes = new AttributesTable();
            attributes.AddAttribute("FOO", "Trond");

            var feature = new Feature(Factory.CreateMultiLineString(new[] { lineString }), attributes);
            var features = new Feature[1];
            features[0] = feature;

            var shpWriter = new ShapefileDataWriter("ZMtest", Factory)
            {
                Header = ShapefileDataWriter.GetHeader(features[0], features.Length)
            };
            shpWriter.Write(features);

            // Now let's read the file and verify that we got Z and M back
            var factory = new GeometryFactory(DotSpatialAffineCoordinateSequenceFactory.Instance);

            using (var reader = new ShapefileDataReader("ZMtest", factory))
            {
                reader.Read();
                var geom = reader.Geometry;

                for (var i = 0; i < 3; i++)
                {
                    var c = geom.Coordinates[i];
                    Assert.AreEqual(i + 1, c.Z);
                }

                if (testM)
                {
                    sequence = ((ILineString)geom).CoordinateSequence;
                    for (var i = 0; i < 3; i++)
                    {
                        Assert.AreEqual(sequence.GetOrdinate(i, Ordinate.M), 11 + i);
                    }
                }

                // Run a simple attribute test too
                var v = reader.GetString(0);
                Assert.AreEqual(v, "Trond");
            }
        }
Beispiel #9
0
        /// <summary>
        /// Finds number of players for each team at a coordinate at rolls to find a winner
        /// 
        /// </summary>
        public void RollForEngagement(Coordinate coordinate, Match match)
        {
            List<Player> homePlayersAtCoordinate = new List<Player>();
            List<Player> awayPlayerAtCoordinate = new List<Player>();

            foreach (Player somePlayer in match.GetPlayersAtCoordinate(coordinate, match))
            {
                if (somePlayer.Team.TeamName == match.HomeTeam.TeamName)
                {
                    homePlayersAtCoordinate.Add(somePlayer);
                }
                else
                {
                    awayPlayerAtCoordinate.Add(somePlayer);
                }
            }

            Console.WriteLine(match.HomeTeam.TeamName + " has " + homePlayersAtCoordinate.Count + " players at coordinate 2,2");
            Console.WriteLine(match.AwayTeam.TeamName + " has " + awayPlayerAtCoordinate.Count + " players at coordinate 2,2");

            //roll for greek players at coordinate
            Random rnd = new Random();

            int rollHome = rnd.Next(1, 7);
            int rollAway = rnd.Next(1, 7);

            Console.WriteLine(match.HomeTeam.TeamName + " rolls " + rollHome);
            Console.WriteLine(match.AwayTeam.TeamName + " rolls " + rollAway);

            //+2 til roll pr. player at coordinate.
            int modifiedGreekRoll = rollHome + homePlayersAtCoordinate.Count * 2;
            int modifiedOlsenRoll = rollAway + awayPlayerAtCoordinate.Count * 2;

            Console.WriteLine("greek modified roll is" + modifiedGreekRoll);
            Console.WriteLine("Olsen modified roll is" + modifiedOlsenRoll);

            ResultOfEngagement engagementResult = FindWinner(match, modifiedGreekRoll, modifiedOlsenRoll);

            var downedPlayer = new Player();
            //add effect (down player, equals half a player next round and can't move.
            if (engagementResult != ResultOfEngagement.Tie)
            {
                downedPlayer = EffectOfEngangement(engagementResult, homePlayersAtCoordinate, awayPlayerAtCoordinate);
            }
            else
            {
                Console.WriteLine("Its was a tie, no player downed");
            }

            if (downedPlayer != null)
            {
                if (match.MatchBall.PlayerWithBall == downedPlayer)
                {
                    //give player to another player at that coordinate
                }
                Console.WriteLine(downedPlayer.Name + " " + downedPlayer.State);
            }

            Console.WriteLine(engagementResult.ToString());
        }
Beispiel #10
0
 public Build(BlockTemplate BlockType, Coordinate Location)
     : base(Location)
 {
     this.BlockType = BlockType;
     MarkerTile = TileNames.TaskIconBlank;
     GnomeIcon = TileNames.TaskIconBuild;
 }
 public Pixel(Coordinate position, int r, int g, int b)
     : this(position)
 {
     this.R = r;
     this.G = g;
     this.B = b;
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="pts1"></param>
        /// <param name="orientation1"></param>
        /// <param name="pts2"></param>
        /// <param name="orientation2"></param>
        /// <returns></returns>
        private static int CompareOriented(Coordinate[] pts1, bool orientation1, Coordinate[] pts2, bool orientation2)
        {
            int dir1 = orientation1 ? 1 : -1;
            int dir2 = orientation2 ? 1 : -1;
            int limit1 = orientation1 ? pts1.Length : -1;
            int limit2 = orientation2 ? pts2.Length : -1;

            int i1 = orientation1 ? 0 : pts1.Length - 1;
            int i2 = orientation2 ? 0 : pts2.Length - 1;
            while (true)
            {
                int compPt = pts1[i1].CompareTo(pts2[i2]);
                if (compPt != 0)
                    return compPt;

                i1 += dir1;
                i2 += dir2;
                bool done1 = i1 == limit1;
                bool done2 = i2 == limit2;
                if(done1 && !done2)
                    return -1;
                if(!done1 && done2)
                    return 1;
                if(done1 && done2)
                    return 0;
            }
        }
 /// <summary>
 /// Adds a point to the current line.
 /// </summary>
 /// <param name="pt">The <see cref="Coordinate" /> to add.</param>
 /// <param name="allowRepeatedPoints">If <c>true</c>, allows the insertions of repeated points.</param>
 public void Add(Coordinate pt, bool allowRepeatedPoints)
 {
     if (_coordList == null)
         _coordList = new CoordinateList();
     _coordList.Add(pt, allowRepeatedPoints);
     _lastPt = pt;
 }
Beispiel #14
0
 public bool is_square_at(Coordinate coordinate)
 {
     if (coordinate.Y > 2 || coordinate.X > 2)
         return false;
     else
         return true;
 }
Beispiel #15
0
        /// <summary>
        /// Initializes the NMEA Geographic position, Latitude and Longitude and parses an NMEA sentence
        /// </summary>
        /// <param name="NMEAsentence"></param>
        public GPGLL(string NMEAsentence)
        {
            try
            {
                //Split into an array of strings.
                string[] split = NMEAsentence.Split(new Char[] { ',' });

                try
                {
                    _position = new Coordinate(GPSHandler.GPSToDecimalDegrees(split[3], split[4]),
                                                GPSHandler.GPSToDecimalDegrees(split[1], split[2]));
                }
                catch { _position = null; }

                try
                {
                    _timeOfSolution = new TimeSpan(int.Parse(split[5].Substring(0, 2)),
                                                    int.Parse(split[5].Substring(2, 2)),
                                                    int.Parse(split[5].Substring(4)));
                }
                catch
                {
                    _timeOfSolution = null; // TimeSpan.Zero;
                }
                _dataValid = (split[6] == "A");
            }
            catch { }
        }
Beispiel #16
0
 public TundraTile(Coordinate position)
 {
     _painter = new TundraTilePainter();
     _name = MainStrings.TundraTileName;
     _properties = new TileProperties(0, 30, position, -20);
     _effects = new TilePropertiesForEffects();
 }
 /// <summary>
 /// Creates an AffineTransformation defined by a single control vector. A
 /// control vector consists of a source point and a destination point, which is
 /// the image of the source point under the desired transformation. This
 /// produces a translation.
 /// </summary>
 /// <param name="src0">The start point of the control vector</param>
 /// <param name="dest0">The end point of the control vector</param>
 /// <returns>The computed transformation</returns>
 public static AffineTransformation CreateFromControlVectors(Coordinate src0,
         Coordinate dest0)
 {
     double dx = dest0.X - src0.X;
     double dy = dest0.Y - src0.Y;
     return AffineTransformation.TranslationInstance(dx, dy);
 }
        /// <summary> 
        /// Computes the "edge distance" of an intersection point p along a segment.
        /// The edge distance is a metric of the point along the edge.
        /// The metric used is a robust and easy to compute metric function.
        /// It is not equivalent to the usual Euclidean metric.
        /// It relies on the fact that either the x or the y ordinates of the
        /// points in the edge are unique, depending on whether the edge is longer in
        /// the horizontal or vertical direction.
        /// NOTE: This function may produce incorrect distances
        /// for inputs where p is not precisely on p1-p2
        /// (E.g. p = (139,9) p1 = (139,10), p2 = (280,1) produces distanct 0.0, which is incorrect.
        /// My hypothesis is that the function is safe to use for points which are the
        /// result of rounding points which lie on the line, but not safe to use for truncated points.
        /// </summary>
        public static double ComputeEdgeDistance(Coordinate p, Coordinate p0, Coordinate p1)
        {
            var dx = Math.Abs(p1.X - p0.X);
            var dy = Math.Abs(p1.Y - p0.Y);

            var dist = -1.0;   // sentinel value
            if (p.Equals(p0)) 
                dist = 0.0;            
            else if (p.Equals(p1)) 
            {
                dist = dx > dy ? dx : dy;
            }
            else 
            {
                double pdx = Math.Abs(p.X - p0.X);
                double pdy = Math.Abs(p.Y - p0.Y);
                dist = dx > dy ? pdx : pdy;

                // <FIX>: hack to ensure that non-endpoints always have a non-zero distance
                if (dist == 0.0 && ! p.Equals2D(p0))                
                    dist = Math.Max(pdx, pdy);
                
            }
            Assert.IsTrue(!(dist == 0.0 && ! p.Equals(p0)), "Bad distance calculation");
            return dist;
        }
Beispiel #19
0
 /// <summary>
 /// Creates a specified number of random point features inside a single polygon feature. 
 /// </summary>
 /// <param name="ConstrainingFeature">Random points will be generated inside this polygon feature.</param>
 /// <param name="NumberOfPoints">The number of points to be randomly generated.</param>
 /// <returns>A point feature set with the randomly created features.</returns>
 public static FeatureSet RandomPoints(Feature ConstrainingFeature, int NumberOfPoints)
 {
     //This function generates random points within the boundaries of one polygon feature
     FeatureSet fsOut = new FeatureSet();
     fsOut.FeatureType = FeatureType.Point;
     Coordinate c = new Coordinate();
     Random r = new Random();
     int i = 0;
     while (i < NumberOfPoints)
     {
         c = new Coordinate();
         //make a random point somewhere in the rectangular extents of the feature
         double rndx = r.Next(0, 100000) / 100000.0;
         double rndy = r.Next(0, 100000) / 100000.0;
         c.X = rndx * (ConstrainingFeature.Envelope.Right() - ConstrainingFeature.Envelope.Left()) + ConstrainingFeature.Envelope.Left();
         c.Y = rndy * (ConstrainingFeature.Envelope.Top() - ConstrainingFeature.Envelope.Bottom()) + ConstrainingFeature.Envelope.Bottom();
         //check if the point falls within the polygon featureset
         if (ConstrainingFeature.Intersects(c))
         {
             fsOut.AddFeature(new Feature(c));
             i++;
         }
     }
     return fsOut;
 }
Beispiel #20
0
 public static Coordinate PointNotInList(Coordinate[] testPts, Coordinate[] pts)
 {
     foreach (Coordinate testPt in testPts)
         if (!IsInList(testPt, pts))
             return testPt;
     return null;
 }
Beispiel #21
0
        public void addSinglePieceToClusterCorrectLiberties()
        {
            //arrange
            GoBoard testgame = new GoBoard(5);

            Coordinate loc = new Coordinate(3, 3);
            testgame.addPiece(loc, Space.Black);
            PieceCluster simpleCluster = new PieceCluster(loc, Space.Black, testgame);

            Coordinate loc2 = new Coordinate(4, 2);
            testgame.addPiece(loc2, Space.White);

            Coordinate loc3 = new Coordinate(4, 3);
            testgame.addPiece(loc3, Space.Black);
            simpleCluster.piecesAdd(loc3);
            simpleCluster.removeLiberty(loc3);
            simpleCluster.addLibertiesOf(loc3);

            int expected = 5;

            //act
            int actual = simpleCluster.Liberties.Count;

            //assert
            Assert.AreEqual(expected, actual);
        }
        public RemoveBlockMutation(Coordinate Location, Gnome Gnome)
        {
            this.MutationTimeFrame = MutationTimeFrame.BeforeUpdatingConnectivity;

            this.Location = Location;
            this.Gnome = Gnome;
        }
Beispiel #23
0
 public void Multils()
 {
     Random rnd = new Random();
     LineString[] ls = new LineString[40];
     GeoAPI.Geometries.ILineString[] lscheck = new GeoAPI.Geometries.ILineString[40];
     GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory gf = new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory();
     for (int ii = 0; ii < 40; ii++)
     {
         Coordinate[] coord = new Coordinate[36];
         GeoAPI.Geometries.ICoordinate[] coordcheck = new GeoAPI.Geometries.ICoordinate[36];
         for (int i = 0; i < 36; i++)
         {
             coord[i] = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);
             double x = coord[i].X;
             double y = coord[i].Y;
             GisSharpBlog.NetTopologySuite.Geometries.Coordinate c = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(x, y);
             coordcheck[i] = c;
         }
         ls[ii] = new LineString(coord);
         lscheck[ii] = gf.CreateLineString(coordcheck);
     }
     MultiLineString mls = new MultiLineString(ls);
     GeoAPI.Geometries.IMultiLineString mlscheck = gf.CreateMultiLineString(lscheck);
     for (int ii = 0; ii < mls.Coordinates.Count; ii++)
     {
         Assert.AreEqual(mls.Coordinates[ii].X, mlscheck.Coordinates[ii].X);
         Assert.AreEqual(mls.Coordinates[ii].Y, mlscheck.Coordinates[ii].Y);
     }
     Assert.AreEqual(mls.NumGeometries, mlscheck.NumGeometries);
 }
        /// <summary>
        /// Determines whether two lines or line segments intersects
        /// </summary>
        /// <param name="a1">The first point of the first line</param>
        /// <param name="b1">The second point of the first line</param>
        /// <param name="line1Mode">LineMode value that specifies whether A1B1 should be treated as infinite line or as line segment</param>
        /// <param name="a2">The first point of the second line</param>
        /// <param name="b2">The second point of the second line</param>
        /// <param name="line2Mode">LineMode value that specifies whether A2B2 should be treated as infinite line or as line segment</param>
        /// <returns>true if A1B1 intersects A2B2, otherwise returns false</returns>
        public bool Intersects(Coordinate a1, Coordinate b1, LineMode line1Mode, Coordinate a2, Coordinate b2, LineMode line2Mode)
        {
            double paramA1 = b1.Y - a1.Y;
            double paramB1 = a1.X - b1.X;
            double paramC1 = paramA1 * a1.X + paramB1 * a1.Y;

            double paramA2 = b2.Y - a2.Y;
            double paramB2 = a2.X - b2.X;
            double paramC2 = paramA2 * a2.X + paramB2 * a2.Y;

            double det = paramA1 * paramB2 - paramA2 * paramB1;
            if (det == 0) {
                return false;
            }
            else {
                double x = (paramB2 * paramC1 - paramB1 * paramC2) / det;
                double y = (paramA1 * paramC2 - paramA2 * paramC1) / det;

                if (line1Mode == LineMode.LineSegment) {
                    if (x < Math.Min(a1.X, b1.X) || x > Math.Max(a1.X, b1.X) || y < Math.Min(a1.Y, b1.Y) || y > Math.Max(a1.Y, b1.Y)) {
                        return false;
                    }
                }

                if (line2Mode == LineMode.LineSegment) {
                    if (x < Math.Min(a2.X, b2.X) || x > Math.Max(a2.X, b2.X) || y < Math.Min(a2.Y, b2.Y) || y > Math.Max(a2.Y, b2.Y)) {
                        return false;
                    }
                }

                return true;
            }
        }
Beispiel #25
0
 /// <summary>
 /// Creates a new instance of TextSymbolizer
 /// </summary>
 public LabelSymbolizer()
 {
     Angle = 0;
     UseAngle = false;
     LabelAngleField = null;
     UseLabelAngleField = false;
     BorderVisible = false;
     BorderColor = Color.Black;
     BackColor = Color.AntiqueWhite;
     BackColorEnabled = false;
     DropShadowColor = Color.FromArgb(20, 0, 0, 0);
     DropShadowEnabled = false;
     DropShadowGeographicOffset = new Coordinate(0, 0);
     DropShadowPixelOffset = new PointF(2F, 2F);
     FontSize = 10F;
     FontFamily = "Arial Unicode MS";
     FontStyle = FontStyle.Regular;
     FontColor = Color.Black;
     HaloColor = Color.White;
     HaloEnabled = false;
     ScaleMode = ScaleMode.Symbolic;
     LabelPlacementMethod = LabelPlacementMethod.Centroid;
     PartsLabelingMethod = PartLabelingMethod.LabelLargestPart;
     PreventCollisions = true;
     PriorityField = "FID";
     Orientation = ContentAlignment.MiddleCenter;
 }
Beispiel #26
0
 public JungleTile(Coordinate position)
 {
     _painter = new JungleTilePainter();
     _name = MainStrings.JungleTileName;
     _properties = new TileProperties(85, 20, position, 27);
     _effects = new TilePropertiesForEffects();
 }
 /// <summary>
 /// Computes the cross product of <paramref name="v1"/> and <paramref name="v2"/>
 /// </summary>
 /// <param name="v1">A vector</param>
 /// <param name="v2">A vector</param>
 /// <returns>The cross product of <paramref name="v1"/> and <paramref name="v2"/></returns>
 public static Coordinate CrossProduct(Coordinate v1, Coordinate v2)
 {
     double x = Det(v1.Y, v1.Z, v2.Y, v2.Z);
     double y = -Det(v1.X, v1.Z, v2.X, v2.Z);
     double z = Det(v1.X, v1.Y, v2.X, v2.Y);
     return new Coordinate(x, y, z);
 }
Beispiel #28
0
        /// <summary>
        /// Initializes the NMEA Recommended minimum specific GPS/Transit data and parses an NMEA sentence
        /// </summary>
        /// <param name="NMEAsentence"></param>
        public GPRMC(string NMEAsentence)
        {
            try
            {
                //Split into an array of strings.
                string[] split = NMEAsentence.Split(new Char[] { ',' });

                //Extract date/time
                try
                {
                    string[] DateTimeFormats = { "ddMMyyHHmmss", "ddMMyy", "ddMMyyHHmmss.FFFFFF" };
                    if (split[9].Length >= 6) { //Require at least the date to be present
                        string time = split[9] + split[1]; // +" 0";
                        _timeOfFix = DateTime.ParseExact(time, DateTimeFormats, GPSHandler.numberFormat_EnUS, System.Globalization.DateTimeStyles.AssumeUniversal);
                    }
                    else
                        _timeOfFix = new DateTime();
                }
                catch { _timeOfFix = new DateTime(); }

                if (split[2] == "A")
                    _status = StatusEnum.OK;
                else
                    _status = StatusEnum.Warning;

                _position = new Coordinate(	GPSHandler.GPSToDecimalDegrees(split[5], split[6]),
                                            GPSHandler.GPSToDecimalDegrees(split[3], split[4]));

                GPSHandler.dblTryParse(split[7], out _speed);
                GPSHandler.dblTryParse(split[8], out _course);
                GPSHandler.dblTryParse(split[10], out _magneticVariation);
            }
            catch { }
        }
        /// <summary>
        /// This method handles single points as well as LineStrings.
        /// LineStrings are assumed <b>not</b> to be closed (the function will not
        /// fail for closed lines, but will generate superfluous line caps).
        /// </summary>
        /// <param name="inputPts">The vertices of the line to offset</param>
        /// <param name="distance">The offset distance</param>
        /// <returns>A Coordinate array representing the curve <br/>
        /// or <c>null</c> if the curve is empty
        /// </returns>
        public Coordinate[] GetLineCurve(Coordinate[] inputPts, double distance)
        {
            _distance = distance;

            // a zero or negative width buffer of a line/point is empty
            if (distance < 0.0 && !_bufParams.IsSingleSided) return null;
            if (distance == 0.0) return null;

            var posDistance = Math.Abs(distance);
            var segGen = GetSegmentGenerator(posDistance);
            if (inputPts.Length <= 1)
            {
                ComputePointCurve(inputPts[0], segGen);
            }
            else
            {
                if (_bufParams.IsSingleSided)
                {
                    var isRightSide = distance < 0.0;
                    ComputeSingleSidedBufferCurve(inputPts, isRightSide, segGen);
                }
                else
                    ComputeLineBufferCurve(inputPts, segGen);
            }

            var lineCoord = segGen.GetCoordinates();
            return lineCoord;
        }
Beispiel #30
0
 /// <summary>
 /// Tests whether a triangle is acute. A triangle is acute iff all interior
 /// angles are acute. This is a strict test - right triangles will return
 /// <tt>false</tt> A triangle which is not acute is either right or obtuse.
 /// <para/>
 /// Note: this implementation is not robust for angles very close to 90 degrees.
 /// </summary>
 /// <param name="a">A vertex of the triangle</param>
 /// <param name="b">A vertex of the triangle</param>
 /// <param name="c">A vertex of the triangle</param>
 /// <returns>True if the triangle is acute.</returns>
 public static Boolean IsAcute(Coordinate a, Coordinate b, Coordinate c)
 {
     if (!AngleUtility.IsAcute(a, b, c)) return false;
     if (!AngleUtility.IsAcute(b, c, a)) return false;
     if (!AngleUtility.IsAcute(c, a, b)) return false;
     return true;
 }