Ejemplo n.º 1
0
        /// <summary>
        /// Create line with geo coordinates.
        /// </summary>
        /// <param name="GeoCoordinate1">A geo coordinate.</param>
        /// <param name="GeoVector">A geo vector.</param>
        public GeoLine(GeoCoordinate GeoCoordinate1, GeoVector GeoVector)
        {
            #region Initial Checks

            if (GeoCoordinate1 == null)
            {
                throw new ArgumentNullException("The given left-coordinate must not be null!");
            }

            if (GeoVector == null)
            {
                throw new ArgumentNullException("The given right-coordinate must not be null!");
            }

            #endregion

            this.P1 = GeoCoordinate1;
            this.P2 = new GeoCoordinate(
                Latitude.Parse(GeoCoordinate1.Latitude.Value + GeoVector.P.Latitude.Value),
                Longitude.Parse(GeoCoordinate1.Longitude.Value + GeoVector.P.Longitude.Value)
                );

            this.Length = GeoCoordinate1.DistanceTo(P2);
            this.Tags   = new List <String>();
        }
Ejemplo n.º 2
0
 private Double DotProduct(GeoVector v1, GeoVector v2)
 {
     return
         (
         v1.P.Longitude.Value * v2.P.Longitude.Value +
         v1.P.Latitude.Value * v2.P.Latitude.Value
         );
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Compares two vectors for equality.
        /// </summary>
        /// <param name="IVector">A vector to compare with.</param>
        /// <returns>True if both match; False otherwise.</returns>
        public Boolean Equals(GeoVector IVector)
        {
            if ((Object)IVector == null)
            {
                return(false);
            }

            return(this.P.Longitude.Equals(IVector.P.Longitude) &&
                   this.P.Latitude.Equals(IVector.P.Latitude));
        }
Ejemplo n.º 4
0
        //#region Zero

        ///// <summary>
        ///// Return the zero value of this datatype.
        ///// </summary>
        //public IVector2D<T> Zero
        //{
        //    get
        //    {
        //        return new Vector2D<T>(Math.Zero, Math.Zero);
        //    }
        //}

        //#endregion

        //#region NegativeInfinity

        ///// <summary>
        ///// Return the negative infinity of this datatype.
        ///// </summary>
        //public IVector2D<T> NegativeInfinity
        //{
        //    get
        //    {
        //        return new Vector2D<T>(Math.NegativeInfinity, Math.NegativeInfinity);
        //    }
        //}

        //#endregion

        //#region PositiveInfinity

        ///// <summary>
        ///// Return the positive infinity of this datatype.
        ///// </summary>
        //public IVector2D<T> PositiveInfinity
        //{
        //    get
        //    {
        //        return new Vector2D<T>(Math.PositiveInfinity, Math.PositiveInfinity);
        //    }
        //}

        //#endregion


        //#region Min(params Values)

        ///// <summary>
        ///// A method to get the minimum of an array of Doubles.
        ///// </summary>
        ///// <param name="Values">An array of Doubles.</param>
        ///// <returns>The minimum of all values: Min(a, b, ...)</returns>
        //public IVector2D<T> Min(params IVector2D<T>[] Values)
        //{

        //    if (Values == null || Values.Length == 0)
        //        throw new ArgumentException("The given values must not be null or zero!");

        //    if (Values.Length == 1)
        //        return Values[0];

        //    var _X = Values[0].X;
        //    var _Y = Values[0].Y;

        //    for (var i = Values.Length - 1; i >= 1; i--)
        //    {
        //        _X = Math.Min(_X, Values[i].X);
        //        _Y = Math.Min(_Y, Values[i].Y);
        //    }

        //    return new Vector2D<T>(Math.Zero, Math.Zero, _X, _Y);

        //}

        //#endregion

        //#region Max(params Values)

        ///// <summary>
        ///// A method to get the maximum of an array of Doubles.
        ///// </summary>
        ///// <param name="Values">An array of Doubles.</param>
        ///// <returns>The maximum of all values: Min(a, b, ...)</returns>
        //public IVector2D<T> Max(params IVector2D<T>[] Values)
        //{

        //    if (Values == null || Values.Length == 0)
        //        throw new ArgumentException("The given values must not be null or zero!");

        //    if (Values.Length == 1)
        //        return Values[0];

        //    var _X = Values[0].X;
        //    var _Y = Values[0].Y;

        //    for (var i = Values.Length - 1; i >= 1; i--)
        //    {
        //        _X = Math.Max(_X, Values[i].X);
        //        _Y = Math.Max(_Y, Values[i].Y);
        //    }

        //    return new Vector2D<T>(Math.Zero, Math.Zero, _X, _Y);

        //}

        //#endregion


        //#region Add(params Summands)

        ///// <summary>
        ///// A method to add vectors.
        ///// </summary>
        ///// <param name="Summands">An array of vectors.</param>
        ///// <returns>The addition of all summands: v1 + v2 + ...</returns>
        //public IVector2D<T> Add(params IVector2D<T>[] Summands)
        //{

        //    if (Summands == null || Summands.Length == 0)
        //        throw new ArgumentException("The given summands must not be null!");

        //    if (Summands.Length == 1)
        //        return Summands[0];

        //    var _X = Summands[0].X;
        //    var _Y = Summands[0].Y;

        //    for (var i = Summands.Length - 1; i >= 1; i--)
        //    {
        //        _X = Math.Add(_X, Summands[i].X);
        //        _Y = Math.Add(_Y, Summands[i].Y);
        //    }

        //    return new Vector2D<T>(Math.Zero, Math.Zero, _X, _Y);

        //}

        //#endregion

        //#region Sub(v1, v2)

        ///// <summary>
        ///// A method to sub two vectors.
        ///// </summary>
        ///// <param name="v1">A vector.</param>
        ///// <param name="v2">A vector.</param>
        ///// <returns>The subtraction of v2 from v1: v1 - v2</returns>
        //public IVector2D<T> Sub(IVector2D<T> v1, IVector2D<T> v2)
        //{
        //    return new Vector2D<T>(Math.Sub(v1.X,   v2.X),
        //                           Math.Sub(v1.Y, v2.Y));
        //}

        //#endregion

        //#region Mul(params Multiplicators)

        ///// <summary>
        ///// A method to multiply vectors.
        ///// </summary>
        ///// <param name="Multiplicators">An array of vectors.</param>
        ///// <returns>The multiplication of all multiplicators: v1 * v2 * ...</returns>
        //public IVector2D<T> Mul(params IVector2D<T>[] Multiplicators)
        //{

        //    if (Multiplicators == null || Multiplicators.Length == 0)
        //        throw new ArgumentException("The given multiplicators must not be null!");

        //    if (Multiplicators.Length == 1)
        //        return Multiplicators[0];

        //    var _X = Multiplicators[0].X;
        //    var _Y = Multiplicators[0].Y;

        //    for (var i = Multiplicators.Length - 1; i >= 1; i--)
        //    {
        //        _X = Math.Mul(_X, Multiplicators[i].X);
        //        _Y = Math.Mul(_Y, Multiplicators[i].Y);
        //    }

        //    return new Vector2D<T>(Math.Zero, Math.Zero, _X, _Y);

        //}

        //#endregion

        //#region Mul2(a)

        ///// <summary>
        ///// A method to multiply a vector by 2.
        ///// </summary>
        ///// <param name="v">A vector.</param>
        ///// <returns>The multiplication of v by 2: (2*x, 2*y)</returns>
        //public IVector2D<T> Mul2(IVector2D<T> v)
        //{
        //    return new Vector2D<T>(Math.Mul2(v.X),
        //                           Math.Mul2(v.Y));
        //}

        //#endregion

        //#region Div(v1, v2)

        ///// <summary>
        ///// A method to divide two vectors.
        ///// </summary>
        ///// <param name="v1">A vector.</param>
        ///// <param name="v2">A vector.</param>
        ///// <returns>The division of v1 by v2: v1 / v2</returns>
        //public IVector2D<T> Div(IVector2D<T> v1, IVector2D<T> v2)
        //{
        //    return new Vector2D<T>(Math.Div(v1.X,   v2.X),
        //                           Math.Div(v1.Y, v2.Y));
        //}

        //#endregion

        //#region Div2(v)

        ///// <summary>
        ///// A method to divide a vector by 2.
        ///// </summary>
        ///// <param name="v">A vector.</param>
        ///// <returns>The division of v by 2: v / 2</returns>
        //public IVector2D<T> Div2(IVector2D<T> v)
        //{
        //    return new Vector2D<T>(Math.Div2(v.X),
        //                           Math.Div2(v.Y));
        //}

        //#endregion

        //#region Pow(a, b)

        ///// <summary>
        ///// A method to calculate a Double raised to the specified power.
        ///// </summary>
        ///// <param name="v1">A vector.</param>
        ///// <param name="v2">A vector.</param>
        ///// <returns>The values of v1 raised to the specified power of v2: v1^v2</returns>
        //public IVector2D<T> Pow(IVector2D<T> v1, IVector2D<T> v2)
        //{
        //    return new Vector2D<T>(Math.Pow(v1.X,   v2.X),
        //                           Math.Pow(v1.Y, v2.Y));
        //}

        //#endregion


        //#region Inv(v)

        ///// <summary>
        ///// A method to calculate the inverse value of the given vector.
        ///// </summary>
        ///// <param name="v">A vector.</param>
        ///// <returns>The inverse value of v: -v</returns>
        //public IVector2D<T> Inv(IVector2D<T> v)
        //{
        //    return new Vector2D<T>(Math.Inv(v.X),
        //                           Math.Inv(v.Y));
        //}

        //#endregion

        //#region Abs(v)

        ///// <summary>
        ///// A method to calculate the absolute value of the given vector.
        ///// </summary>
        ///// <param name="v">A vector.</param>
        ///// <returns>The absolute value of v: (|a| |b|)</returns>
        //public IVector2D<T> Abs(IVector2D<T> v)
        //{
        //    return new Vector2D<T>(Math.Abs(v.X),
        //                           Math.Abs(v.Y));
        //}

        //#endregion

        //#region Sqrt(v)

        ///// <summary>
        ///// A method to calculate the square root of the vector.
        ///// </summary>
        ///// <param name="v">A vector.</param>
        ///// <returns>The square root of v: Sqrt(v)</returns>
        //public IVector2D<T> Sqrt(IVector2D<T> v)
        //{
        //    return new Vector2D<T>(Math.Sqrt(v.X),
        //                           Math.Sqrt(v.Y));
        //}

        //#endregion


        //#region Distance(a, b)

        ///// <summary>
        ///// A method to calculate the distance between two vectors.
        ///// </summary>
        ///// <param name="v1">A vector.</param>
        ///// <param name="v2">A vector.</param>
        ///// <returns>The distance between v1 and v2.</returns>
        //public IVector2D<T> Distance(IVector2D<T> v1, IVector2D<T> v2)
        //{
        //    return new Vector2D<T>(Math.Abs(Math.Sub(v1.X,   v2.X)),
        //                           Math.Abs(Math.Sub(v1.Y, v2.Y)));
        //}

        //#endregion

        #endregion


        #region IsParallelTo(Vector)

        /// <summary>
        /// Determines if the given vector is parallel or
        /// antiparallel to this vector.
        /// </summary>
        /// <param name="Vector">A vector.</param>
        public Boolean IsParallelTo(GeoVector Vector)
        {
            var ThisNormVector = this.NormVector;
            var ThatNormVector = Vector.NormVector;

            if ((ThisNormVector.P.Longitude.Value.Equals(ThatNormVector.P.Longitude.Value) &&
                 ThisNormVector.P.Latitude.Value.Equals(ThatNormVector.P.Latitude.Value)) ||
                (ThisNormVector.P.Longitude.Value.Equals(-1 * ThatNormVector.P.Longitude.Value) &&
                 ThisNormVector.P.Latitude.Value.Equals(-1 * ThatNormVector.P.Latitude.Value)))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Create a 2-dimensional vector of type T.
        /// </summary>
        /// <param name="GeoVector1">A vector of type T.</param>
        /// <param name="GeoVector2">A vector of type T.</param>
        public GeoVector(GeoVector GeoVector1, GeoVector GeoVector2)
        {
            #region Initial Checks

            if (GeoVector1 == null)
                throw new ArgumentNullException("The first vector must not be null!");

            if (GeoVector2 == null)
                throw new ArgumentNullException("The second vector must not be null!");

            #endregion

            this.P      = new GeoCoordinate(new Latitude (GeoVector1.P.Latitude.Value  - GeoVector2.P.Latitude.Value),
                                            new Longitude(GeoVector1.P.Longitude.Value - GeoVector2.P.Longitude.Value));

            this.Length = GeoVector1.P.DistanceTo(GeoVector2.P);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Create line with geo coordinates.
        /// </summary>
        /// <param name="GeoCoordinate1">A geo coordinate.</param>
        /// <param name="GeoVector">A geo vector.</param>
        public GeoLine(GeoCoordinate GeoCoordinate1, GeoVector GeoVector)
        {
            #region Initial Checks

            if (GeoCoordinate1 == null)
                throw new ArgumentNullException("The given left-coordinate must not be null!");

            if (GeoVector == null)
                throw new ArgumentNullException("The given right-coordinate must not be null!");

            #endregion

            this.P1     = GeoCoordinate1;
            this.P2     = new GeoCoordinate(new Latitude (GeoCoordinate1.Latitude.Value  + GeoVector.P.Latitude.Value),
                                            new Longitude(GeoCoordinate1.Longitude.Value + GeoVector.P.Longitude.Value));

            this.Length = GeoCoordinate1.DistanceTo(P2);
            this.Tags   = new List<String>();
        }
Ejemplo n.º 7
0
        public Boolean Contains(GeoCoordinate GeoCoordinate)
        {
            var v0 = new GeoVector(P3, P1);
            var v1 = new GeoVector(P2, P1);
            var v2 = new GeoVector(GeoCoordinate, P1);

            var dot00 = DotProduct(v0, v0);
            var dot01 = DotProduct(v0, v1);
            var dot02 = DotProduct(v0, v2);
            var dot11 = DotProduct(v1, v1);
            var dot12 = DotProduct(v1, v2);

            // Compute barycentric coordinates
            var invDenom = 1 / (dot00 * dot11 - dot01 * dot01);
            var u        = (dot11 * dot02 - dot01 * dot12) * invDenom;
            var v        = (dot00 * dot12 - dot01 * dot02) * invDenom;

            // Check if point is in triangle
            return((u >= 0) && (v >= 0) && (u + v < 1));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Create a 2-dimensional vector of type T.
        /// </summary>
        /// <param name="GeoVector1">A vector of type T.</param>
        /// <param name="GeoVector2">A vector of type T.</param>
        public GeoVector(GeoVector GeoVector1, GeoVector GeoVector2)
        {
            #region Initial Checks

            if (GeoVector1 == null)
            {
                throw new ArgumentNullException("The first vector must not be null!");
            }

            if (GeoVector2 == null)
            {
                throw new ArgumentNullException("The second vector must not be null!");
            }

            #endregion

            this.P = new GeoCoordinate(new Latitude(GeoVector1.P.Latitude.Value - GeoVector2.P.Latitude.Value),
                                       new Longitude(GeoVector1.P.Longitude.Value - GeoVector2.P.Longitude.Value));

            this.Length = GeoVector1.P.DistanceTo(GeoVector2.P);
        }
Ejemplo n.º 9
0
 private Double DotProduct(GeoVector v1, GeoVector v2)
 {
     return
     (
        v1.P.Longitude.Value * v2.P.Longitude.Value +
        v1.P.Latitude.Value * v2.P.Latitude.Value
     );
 }
Ejemplo n.º 10
0
        public Boolean Contains(GeoCoordinate GeoCoordinate)
        {
            var v0 = new GeoVector(P3,            P1);
            var v1 = new GeoVector(P2,            P1);
            var v2 = new GeoVector(GeoCoordinate, P1);

            var dot00 = DotProduct(v0, v0);
            var dot01 = DotProduct(v0, v1);
            var dot02 = DotProduct(v0, v2);
            var dot11 = DotProduct(v1, v1);
            var dot12 = DotProduct(v1, v2);

            // Compute barycentric coordinates
            var invDenom = 1 / (dot00 * dot11 - dot01 * dot01);
            var u = (dot11 * dot02 - dot01 * dot12) * invDenom;
            var v = (dot00 * dot12 - dot01 * dot02) * invDenom;

            // Check if point is in triangle
            return (u >= 0) && (v >= 0) && (u + v < 1);
        }
Ejemplo n.º 11
0
 public int CompareTo(GeoVector other)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Determines if the given vector is parallel or
        /// antiparallel to this vector.
        /// </summary>
        /// <param name="Vector">A vector.</param>
        public Boolean IsParallelTo(GeoVector Vector)
        {
            var ThisNormVector = this.NormVector;
            var ThatNormVector = Vector.NormVector;

            if ((ThisNormVector.P.Longitude.Value.Equals(ThatNormVector.P.Longitude.Value) &&
                 ThisNormVector.P.Latitude.Value. Equals(ThatNormVector.P.Latitude.Value)) ||
                (ThisNormVector.P.Longitude.Value.Equals(-1*ThatNormVector.P.Longitude.Value) &&
                 ThisNormVector.P.Latitude.Value. Equals(-1*ThatNormVector.P.Latitude.Value)))
                return true;

            return false;
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Compares two vectors for equality.
        /// </summary>
        /// <param name="IVector">A vector to compare with.</param>
        /// <returns>True if both match; False otherwise.</returns>
        public Boolean Equals(GeoVector IVector)
        {
            if ((Object) IVector == null)
                return false;

            return this.P.Longitude.Equals(IVector.P.Longitude) &&
                   this.P.Latitude. Equals(IVector.P.Latitude);
        }
Ejemplo n.º 14
0
 public int CompareTo(GeoVector other)
 {
     throw new NotImplementedException();
 }