SilverlightMappingToolBasic.IntersectionDetector.FindIntersections C# (CSharp) Method

FindIntersections() public method

public FindIntersections ( ILineSegment testSegment ) : Point>.Dictionary
testSegment ILineSegment
return Point>.Dictionary
        public Dictionary<ILineSegment, Point> FindIntersections(ILineSegment testSegment)
        {
            Dictionary<ILineSegment, Point> intersectingLineSegments = new Dictionary<ILineSegment, Point>();

            double testSegmentCoefficient = testSegment.Coefficient;
            double testSegmentConstant = testSegment.Constant;

            foreach (ILineSegment lineSegment in _lineSegments)
            {
                double lineSegmentCoefficient = lineSegment.Coefficient;

                if (testSegmentCoefficient == lineSegmentCoefficient)
                {
                    continue;
                }

                double lineSegmentConstant = lineSegment.Constant;

                double constantDifference = lineSegmentConstant - testSegmentConstant;
                double coefficientDifference = testSegmentCoefficient - lineSegmentCoefficient;

                double yIntersectCoordinate = ((testSegmentCoefficient * constantDifference) / coefficientDifference) + testSegmentConstant;
                double xIntersectCoordinate = constantDifference / coefficientDifference;

                if ((yIntersectCoordinate > testSegment.PointA.Y && yIntersectCoordinate < testSegment.PointB.Y) || (yIntersectCoordinate < testSegment.PointA.Y && yIntersectCoordinate > testSegment.PointB.Y))
                {
                    if ((xIntersectCoordinate > testSegment.PointA.X && xIntersectCoordinate < testSegment.PointB.X) || (xIntersectCoordinate < testSegment.PointA.X && xIntersectCoordinate > testSegment.PointB.X))
                    {
                        if ((yIntersectCoordinate > lineSegment.PointA.Y && yIntersectCoordinate < lineSegment.PointB.Y) || (yIntersectCoordinate < lineSegment.PointA.Y && yIntersectCoordinate > lineSegment.PointB.Y))
                        {
                            if ((xIntersectCoordinate > lineSegment.PointA.X && xIntersectCoordinate < lineSegment.PointB.X) || (xIntersectCoordinate < lineSegment.PointA.X && xIntersectCoordinate > lineSegment.PointB.X))
                            {
                                Point intersectionPoint = new Point(xIntersectCoordinate, yIntersectCoordinate);

                                LineSegment segment = (LineSegment)lineSegment;

                                intersectingLineSegments.Add(lineSegment, intersectionPoint);
                            }
                        }
                    }
                }
            }

            return intersectingLineSegments;
        }
    }

Usage Example

Esempio n. 1
0
        public ILineSegment Resize(IntersectionDetector detector)
        {
            LineSegment lineSegment = new LineSegment(PointA, PointB, new Point(0, 0));

            lineSegment.Id = Id;
            Dictionary <ILineSegment, Point> intersections = detector.FindIntersections(lineSegment);

            foreach (KeyValuePair <ILineSegment, Point> intersection in intersections)
            {
                if (intersection.Key.TriangulationPoint.X != 0 && intersection.Key.TriangulationPoint.Y != 0)
                {
                    Point closestPoint;

                    if (intersection.Key.TriangulateClosestEndPoint(this, out closestPoint))
                    {
                        if (lineSegment.PointA == closestPoint)
                        {
                            lineSegment.PointA = intersection.Value;
                        }
                        else
                        {
                            lineSegment.PointB = intersection.Value;
                        }
                    }
                }
            }

            return(lineSegment);
        }
All Usage Examples Of SilverlightMappingToolBasic.IntersectionDetector::FindIntersections