예제 #1
0
        /// <summary>
        /// Calculate the intersection point between the segment and line.
        /// </summary>
        /// <param name="sEq">The segment equation.</param>
        /// <param name="lEq">The line equation.</param>
        /// <returns>Returns the intersection point.</returns>
        public static Point GetIntersection(SegmentEquation sEq, LinearEquation lEq)
        {
            var pt = LinearEquation.GetIntersection(sEq, lEq);

            if (sEq.IsPointInRange(pt))
            {
                return(pt);
            }

            return(null);
        }
예제 #2
0
        /// <summary>
        /// Calculate the intersection point between the 2 segments.
        /// </summary>
        /// <param name="eq1">The first segment equation.</param>
        /// <param name="eq2">The second segment equation.</param>
        /// <returns>Returns the intersection point.</returns>
        public static Point GetIntersection(SegmentEquation eq1, SegmentEquation eq2)
        {
            var pt = LinearEquation.GetIntersection(eq1, eq2);

            if (eq1.IsPointInRange(pt) && eq2.IsPointInRange(pt))
            {
                return(pt);
            }

            return(null);
        }
예제 #3
0
        /// <summary>
        /// Calculate the intersection point between the segment and line (Special).
        /// </summary>
        /// <param name="sEq">The segment equation.</param>
        /// <param name="lEq">The line equation.</param>
        /// <returns>Returns the intersection points.</returns>
        public static Point GetIntersectionSp(SegmentEquation sEq, LinearEquation lEq)
        {
            var pt = SegmentEquation.GetIntersection(sEq, lEq);

            if (pt == sEq.endpoint1)
            {
                if (pt.Y <= sEq.endpoint2.Y)
                {
                    pt = null;
                }
            }
            else if (pt == sEq.endpoint2)
            {
                if (pt.Y <= sEq.endpoint1.Y)
                {
                    pt = null;
                }
            }

            return(pt);
        }
예제 #4
0
        /// <summary>
        /// Calculate the intersection point between the 2 lines.
        /// </summary>
        /// <param name="eq1">The first line equation.</param>
        /// <param name="eq2">The second line equation.</param>
        /// <returns>Return the intersection point.</returns>
        public static Point GetIntersection(LinearEquation eq1, LinearEquation eq2)
        {
            if (eq1.slope == eq2.slope)
            {
                return(null);
            }

            if (double.IsInfinity(eq1.slope))
            {
                return(new Point(eq1.bias, eq2.GetCoordY(eq1.bias)));
            }

            if (double.IsInfinity(eq2.slope))
            {
                return(new Point(eq2.bias, eq1.GetCoordY(eq2.bias)));
            }

            double x = (eq2.bias - eq1.bias) / (eq1.slope - eq2.slope);
            double y = eq1.GetCoordY(x);

            return(new Point(x, y));
        }
예제 #5
0
        /// <summary>
        /// Judge wether the specified point lies within the interior or on the boundary of the specified polygon.
        /// </summary>
        /// <param name="pt">The specified point.</param>
        /// <returns>Return true if the specified point intersects the polygon, otherwise false.</returns>
        public bool IsIntersects(Point pt)
        {
            var line = new LinearEquation(pt, LinearType.ParallelXAxis);
            var pts = SegmentEquation.GetIntersectionSp(this.sides, line);
            int counter = 0;
            foreach (var point in pts)
            {
                if (point == pt)
                {
                    return true;
                }
                else
                {
                    if (point.X < pt.X)
                    {
                        counter++;
                    }
                }
            }

            return counter % 2 == 1;
        }
        /// <summary>
        /// Judge wether the specified point lies within the interior or on the boundary of the specified polygon.
        /// </summary>
        /// <param name="pt">The specified point.</param>
        /// <returns>Return true if the specified point intersects the polygon, otherwise false.</returns>
        public bool IsIntersects(Point pt)
        {
            var line    = new LinearEquation(pt, LinearType.ParallelXAxis);
            var pts     = SegmentEquation.GetIntersectionSp(this.sides, line);
            int counter = 0;

            foreach (var point in pts)
            {
                if (point == pt)
                {
                    return(true);
                }
                else
                {
                    if (point.X < pt.X)
                    {
                        counter++;
                    }
                }
            }

            return(counter % 2 == 1);
        }
        /// <summary>
        /// Calculate the intersection points when a line across many segments (Special).
        /// </summary>
        /// <param name="sEqs">The segment equations.</param>
        /// <param name="lEq">The line equation.</param>
        /// <returns>Returns the intersection points.</returns>
        public static List<Point> GetIntersectionSp(IEnumerable<SegmentEquation> sEqs, LinearEquation lEq)
        {
            var pts = new List<Point>();
            foreach (var sEq in sEqs)
            {
                var pt = SegmentEquation.GetIntersectionSp(sEq, lEq);
                if (null != pt && sEq.IsPointInRange(pt))
                {
                    pts.Add(pt);
                }
            }

            return pts;
        }
        /// <summary>
        /// Calculate the intersection point between the segment and line (Special).
        /// </summary>
        /// <param name="sEq">The segment equation.</param>
        /// <param name="lEq">The line equation.</param>
        /// <returns>Returns the intersection points.</returns>
        public static Point GetIntersectionSp(SegmentEquation sEq, LinearEquation lEq)
        {
            var pt = SegmentEquation.GetIntersection(sEq, lEq);
            if (pt == sEq.endpoint1)
            {
                if (pt.Y <= sEq.endpoint2.Y)
                {
                    pt = null;
                }
            }
            else if (pt == sEq.endpoint2)
            {
                if (pt.Y <= sEq.endpoint1.Y)
                {
                    pt = null;
                }
            }

            return pt;
        }
        /// <summary>
        /// Calculate the intersection point between the segment and line.
        /// </summary>
        /// <param name="sEq">The segment equation.</param>
        /// <param name="lEq">The line equation.</param>
        /// <returns>Returns the intersection point.</returns>
        public static Point GetIntersection(SegmentEquation sEq, LinearEquation lEq)
        {
            var pt = LinearEquation.GetIntersection(sEq, lEq);
            if (sEq.IsPointInRange(pt))
            {
                return pt;
            }

            return null;
        }
예제 #10
0
        /// <summary>
        /// Calculate the intersection points when a line across many segments (Special).
        /// </summary>
        /// <param name="sEqs">The segment equations.</param>
        /// <param name="lEq">The line equation.</param>
        /// <returns>Returns the intersection points.</returns>
        public static List <Point> GetIntersectionSp(IEnumerable <SegmentEquation> sEqs, LinearEquation lEq)
        {
            var pts = new List <Point>();

            foreach (var sEq in sEqs)
            {
                var pt = SegmentEquation.GetIntersectionSp(sEq, lEq);
                if (null != pt && sEq.IsPointInRange(pt))
                {
                    pts.Add(pt);
                }
            }

            return(pts);
        }
예제 #11
0
        /// <summary>
        /// Calculate the intersection point between the 2 lines.
        /// </summary>
        /// <param name="eq1">The first line equation.</param>
        /// <param name="eq2">The second line equation.</param>
        /// <returns>Return the intersection point.</returns>
        public static Point GetIntersection(LinearEquation eq1, LinearEquation eq2)
        {
            if (eq1.slope == eq2.slope)
            {
                return null;
            }

            if (double.IsInfinity(eq1.slope))
            {
                return new Point(eq1.bias, eq2.GetCoordY(eq1.bias));
            }

            if (double.IsInfinity(eq2.slope))
            {
                return new Point(eq2.bias, eq1.GetCoordY(eq2.bias));
            }

            double x = (eq2.bias - eq1.bias) / (eq1.slope - eq2.slope);
            double y = eq1.GetCoordY(x);

            return new Point(x, y);
        }