Example #1
0
 public bool BelongsToLine(StraightLine L2)
 {
     if (IsVertical != L2.IsVertical)
     {
         return(false);
     }
     if (IsVertical && L2.IsVertical)
     {
         return(A_Global.X == L2.GetX(0));
     }
     return(Gradient == L2.Gradient &&
            Intercept == L2.Intercept);
 }
Example #2
0
        /// <summary>
        /// Returns true if the lines are equal, false if they are not.
        /// </summary>
        /// <param name="lineA">First line to test.</param>
        /// <param name="lineB">Second Line to test.</param>
        /// <param name="intersection">The point of intersection.</param>
        /// <returns>True if the lines are equal</returns>
        public bool GetIntersection(StraightLine lineA, StraightLine lineB, out Vector2 intersection)
        {
            float x;
            float y;
            bool  aV = lineA.IsVertical;
            bool  bV = lineB.IsVertical;

            intersection = new Vector2();

            //Lines are equal: intersection.
            if (lineA.Equals(lineB))
            {
                return(true);
            }

            //Lines are parallel: no intersection.
            if (lineA.IsParallel(lineB))
            {
                return(false);
            }

            if (aV && !bV)
            {
                x            = -lineA.C / lineA.A;
                y            = (-lineB.A * x - lineB.C) / lineB.B;
                intersection = new Vector2(x, y);
                return(true);
            }
            if (!aV && bV)
            {
                x            = lineB.GetX(0);
                y            = (-lineA.A * x - lineA.C) / lineA.B;
                intersection = new Vector2(x, y);
                return(true);
            }
            if (!aV && !bV)
            {
                x            = (lineB.Intercept - lineA.Intercept) / (lineA.Gradient - lineB.Gradient);
                y            = lineA.Gradient * x + lineA.Intercept;
                intersection = new Vector2(x, y);
                return(true);
            }

            throw new Exception("Well that wasn't supposed to happen...");
        }
        /// <summary>
        /// Returns true if the lines are equal, false if they are not.
        /// </summary>
        /// <param name="lineA">First line to test.</param>
        /// <param name="lineB">Second Line to test.</param>
        /// <param name="intersection">The point of intersection.</param>
        /// <returns>True if the lines are equal</returns>
        public bool GetIntersection(StraightLine lineA, StraightLine lineB, out Vector2 intersection)
        {
            float x;
            float y;
            bool aV = lineA.IsVertical;
            bool bV = lineB.IsVertical;
            intersection = new Vector2();

            //Lines are equal: intersection.
            if (lineA.Equals(lineB))
                return true;

            //Lines are parallel: no intersection.
            if (lineA.IsParallel(lineB))
                return false;

            if (aV && !bV)
            {
                x = -lineA.C / lineA.A;
                y = (-lineB.A * x - lineB.C) / lineB.B;
                intersection = new Vector2(x, y);
                return true;
            }
            if (!aV && bV)
            {
                x = lineB.GetX(0);
                y = (-lineA.A * x - lineA.C) / lineA.B;
                intersection = new Vector2(x, y);
                return true;
            }
            if (!aV && !bV)
            {
                x = (lineB.Intercept - lineA.Intercept) / (lineA.Gradient - lineB.Gradient);
                y = lineA.Gradient * x + lineA.Intercept;
                intersection = new Vector2(x, y);
                return true;
            }

            throw new Exception("Well that wasn't supposed to happen...");
        }
Example #4
0
 public bool BelongsToLine(StraightLine L2)
 {
     if (IsVertical != L2.IsVertical)
         return false;
     if (IsVertical && L2.IsVertical)
         return A_Global.X == L2.GetX(0);
     return Gradient == L2.Gradient
         && Intercept == L2.Intercept;
 }