Ejemplo n.º 1
0
        /// <summary>
        /// Checks if the given first pixel is within the circle
        /// defined by the remaining three edge pixels.
        /// </summary>
        /// <param name="Pixel">The pixel to be checked.</param>
        /// <param name="EdgePixel1">The first edge pixel defining a circle.</param>
        /// <param name="EdgePixel2">The second edge pixel defining a circle.</param>
        /// <param name="EdgePixel3">The third edge pixel defining a circle.</param>
        public static Boolean IsInCircle(GeoCoordinate Pixel, GeoCoordinate EdgePixel1, GeoCoordinate EdgePixel2, GeoCoordinate EdgePixel3)
        {
            #region Initial Checks

            if (Pixel == null)
            {
                throw new ArgumentNullException("The given first pixel must not be null!");
            }

            if (EdgePixel1 == null)
            {
                throw new ArgumentNullException("The given first edgepixel must not be null!");
            }

            if (EdgePixel2 == null)
            {
                throw new ArgumentNullException("The given second edgepixel must not be null!");
            }

            if (EdgePixel3 == null)
            {
                throw new ArgumentNullException("The given third edgepixel must not be null!");
            }

            #endregion

            #region Math Checks

            if (EdgePixel1.Equals(EdgePixel2) ||
                EdgePixel1.Equals(EdgePixel3) ||
                EdgePixel2.Equals(EdgePixel3))
            {
                throw new ArgumentException("All distances between the pixels must be larger than zero!");
            }

            if (EdgePixel1.Longitude.Value.Equals(EdgePixel2.Longitude.Value) &&
                EdgePixel2.Longitude.Value.Equals(EdgePixel3.Longitude.Value))
            {
                throw new ArgumentException("All three pixels must not be on a single line!");
            }

            if (EdgePixel1.Latitude.Value.Equals(EdgePixel2.Latitude.Value) &&
                EdgePixel2.Latitude.Value.Equals(EdgePixel3.Latitude.Value))
            {
                throw new ArgumentException("All three pixels must not be on a single line!");
            }

            #endregion

            var _Line12 = new GeoLine(EdgePixel1, EdgePixel2);
            var _Line23 = new GeoLine(EdgePixel2, EdgePixel3);

            var Center = new GeoLine(_Line12.Center, _Line12.Normale).
                         Intersection(
                new GeoLine(_Line23.Center, _Line23.Normale));

            return(Center.DistanceTo(Pixel) <= Center.DistanceTo(EdgePixel1));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a circumcircle of type T based on three pixels.
        /// </summary>
        /// <param name="Pixel1">The first pixel of the triangle.</param>
        /// <param name="Pixel2">The second pixel of the triangle.</param>
        /// <param name="Pixel3">The third pixel of the triangle.</param>
        public GeoCircle(GeoCoordinate Pixel1, GeoCoordinate Pixel2, GeoCoordinate Pixel3)
        {
            #region Initial Checks

            if (Pixel1 == null)
            {
                throw new ArgumentNullException("The given first pixel must not be null!");
            }

            if (Pixel2 == null)
            {
                throw new ArgumentNullException("The given second pixel must not be null!");
            }

            if (Pixel3 == null)
            {
                throw new ArgumentNullException("The given third pixel must not be null!");
            }

            #endregion

            #region Math Checks

            if (Pixel1.Equals(Pixel2) ||
                Pixel1.Equals(Pixel3) ||
                Pixel2.Equals(Pixel3))
            {
                throw new ArgumentException("All distances between the pixels must be larger than zero!");
            }

            //if (Pixel1.Longitude.Value.Equals(Pixel2.Longitude.Value) &&
            //    Pixel2.Longitude.Value.Equals(Pixel3.Longitude.Value))
            //    throw new ArgumentException("All three pixels must not be on a single line!");

            //if (Pixel1.Latitude.Value.Equals(Pixel2.Latitude.Value) &&
            //    Pixel2.Latitude.Value.Equals(Pixel3.Latitude.Value))
            //    throw new ArgumentException("All three pixels must not be on a single line!");

            #endregion

            var _Line12 = new GeoLine(Pixel1, Pixel2);
            var _Line23 = new GeoLine(Pixel2, Pixel3);

            this.Center = new GeoLine(_Line12.Center, _Line12.Normale).
                          Intersection(
                new GeoLine(_Line23.Center, _Line23.Normale));

            this.Radius = (Center != null) ? Center.DistanceTo(Pixel1) : 0;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create a triangle of type T.
        /// </summary>
        /// <param name="Pixel1">The first pixel of the triangle.</param>
        /// <param name="Pixel2">The second pixel of the triangle.</param>
        /// <param name="Pixel3">The third pixel of the triangle.</param>
        public GeoTriangle(GeoCoordinate Pixel1, GeoCoordinate Pixel2, GeoCoordinate Pixel3)
        {
            #region Initial Checks

            if (Pixel1 == null)
            {
                throw new ArgumentNullException("The given first pixel must not be null!");
            }

            if (Pixel2 == null)
            {
                throw new ArgumentNullException("The given second pixel must not be null!");
            }

            if (Pixel3 == null)
            {
                throw new ArgumentNullException("The given third pixel must not be null!");
            }

            #endregion

            #region Math Checks

            if (Pixel1.Equals(Pixel2) ||
                Pixel1.Equals(Pixel3) ||
                Pixel2.Equals(Pixel3))
            {
                throw new ArgumentException("All distances between the pixels must be larger than zero!");
            }

            //if (Pixel1.Longitude.Equals(Pixel2.Longitude) &&
            //    Pixel2.Longitude.Equals(Pixel3.Longitude))
            //    throw new ArgumentException("All three pixels must not be on a single line!");

            //if (Pixel1.Latitude.Equals(Pixel2.Latitude) &&
            //    Pixel2.Latitude.Equals(Pixel3.Latitude))
            //    throw new ArgumentException("All three pixels must not be on a single line!");

            #endregion

            #region Sort Pixels

            // Sort by x-coordinate.
            while (true)
            {
                if (Pixel1.Longitude > Pixel2.Longitude)
                {
                    GeoCoordinate.Swap(ref Pixel1, ref Pixel2);
                    continue;
                }

                if (Pixel1.Longitude > Pixel3.Longitude)
                {
                    GeoCoordinate.Swap(ref Pixel1, ref Pixel3);
                    continue;
                }

                if (Pixel2.Longitude > Pixel3.Longitude)
                {
                    GeoCoordinate.Swap(ref Pixel2, ref Pixel3);
                    continue;
                }

                break;
            }

            // Sort by y-coordinate if x-coordinates are the same
            if (Pixel1.Longitude.Equals(Pixel2.Longitude))
            {
                if (Pixel1.Latitude > Pixel2.Latitude)
                {
                    GeoCoordinate.Swap(ref Pixel1, ref Pixel2);
                }
            }

            if (Pixel2.Longitude.Equals(Pixel3.Longitude))
            {
                if (Pixel2.Latitude > Pixel3.Latitude)
                {
                    GeoCoordinate.Swap(ref Pixel1, ref Pixel2);
                }
            }

            #endregion

            this.P1 = Pixel1;
            this.P2 = Pixel2;
            this.P3 = Pixel3;

            this.E12 = new GeoLine(P1, P2);
            this.E23 = new GeoLine(P2, P3);
            this.E31 = new GeoLine(P3, P1);

            this._Borders = new GeoLine[3] {
                E12, E23, E31
            };

            this.Tags = new List <String>();
        }