Пример #1
0
        public LineSegment(PointXY startPoint, PointXY endPoint)
        {
            if (startPoint.X < endPoint.X)
            {
                StartPoint = startPoint;
                EndPoint   = endPoint;
            }
            else if ((startPoint.X == endPoint.X) && (startPoint.Y < endPoint.Y))
            {
                StartPoint = startPoint;
                EndPoint   = endPoint;
            }
            else
            {
                StartPoint = endPoint;
                EndPoint   = startPoint;
            }

            // Case of line parallel to the y-axis
            if (StartPoint.X == EndPoint.X)
            {
                EndPoint.X = endPoint.X + 1;
            }

            M = (EndPoint.Y - StartPoint.Y) / (EndPoint.X - StartPoint.X);
            B = StartPoint.Y - (M * StartPoint.X);

            // Length
            Length = Math.Sqrt(Math.Pow(EndPoint.Y - StartPoint.Y, 2) + Math.Pow(EndPoint.X - StartPoint.X, 2));
        }
Пример #2
0
        public IntersectionPoint(LineSegment lineT, LineSegment lineV)
        {
            LineT = lineT;
            LineV = lineV;

            // Intersection Points
            PointOfIntersection   = new PointXY(0, 0);
            PointOfIntersection.X = (lineV.B - lineT.B) / (lineT.M - lineV.M);
            PointOfIntersection.Y = (lineT.M * PointOfIntersection.X) + lineT.B;

            // Second and Penult
            List <double> pointsX = new List <double> {
                lineT.StartPoint.X, lineT.EndPoint.X, lineV.StartPoint.X, lineV.EndPoint.X
            };
            var pointsXinOrder = pointsX.OrderBy(x => x).ToList();

            List <double> pointsY = new List <double> {
                lineT.StartPoint.Y, lineT.EndPoint.Y, lineV.StartPoint.Y, lineV.EndPoint.Y
            };
            var pointsYinOrder = pointsY.OrderBy(y => y).ToList();

            XSecond = pointsXinOrder[1];
            YSecond = pointsYinOrder[1];
            XPenult = pointsXinOrder[2];
            YPenult = pointsYinOrder[2];

            // Intersection
            if ((PointOfIntersection.X > XSecond) && (PointOfIntersection.X < XPenult) && (PointOfIntersection.Y > YSecond) && (PointOfIntersection.Y < YPenult))
            {
                Intersection = true;
            }
            else
            {
                Intersection = false;
            }
        }