SilverlightMappingToolBasic.IntersectionDetector.FindIntersection C# (CSharp) Method

FindIntersection() public method

public FindIntersection ( ILineSegment testSegment, ILineSegment &intersection, Point &intersectionCoordinates ) : bool
testSegment ILineSegment
intersection ILineSegment
intersectionCoordinates Point
return bool
        public bool FindIntersection(ILineSegment testSegment, out ILineSegment intersection, out Point intersectionCoordinates)
        {
            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)) || testSegment.IgnoreLength)
                //{
                //    if (!((xIntersectCoordinate > testSegment.PointA.X && xIntersectCoordinate > testSegment.PointB.X) || (xIntersectCoordinate < testSegment.PointA.X && xIntersectCoordinate < testSegment.PointB.X)) || testSegment.IgnoreLength)
                //    {
                //        if (!((yIntersectCoordinate > lineSegment.PointA.Y && yIntersectCoordinate > lineSegment.PointB.Y) || (yIntersectCoordinate < lineSegment.PointA.Y && yIntersectCoordinate < lineSegment.PointB.Y)) || lineSegment.IgnoreLength)
                //        {
                            //if (!((xIntersectCoordinate > lineSegment.PointA.X && xIntersectCoordinate > lineSegment.PointB.X) || (xIntersectCoordinate < lineSegment.PointA.X && xIntersectCoordinate < lineSegment.PointB.X)) || lineSegment.IgnoreLength)
                            //{
                if ((yIntersectCoordinate < lineSegment.PointA.Y && yIntersectCoordinate > lineSegment.PointB.Y) || (yIntersectCoordinate > lineSegment.PointA.Y && yIntersectCoordinate < lineSegment.PointB.Y) || lineSegment.IgnoreLength)
                {
                    if ((xIntersectCoordinate < lineSegment.PointA.X && xIntersectCoordinate > lineSegment.PointB.X) || (xIntersectCoordinate > lineSegment.PointA.X && xIntersectCoordinate < lineSegment.PointB.X) || lineSegment.IgnoreLength)
                    {
                        intersection = lineSegment;
                        intersectionCoordinates = new Point(xIntersectCoordinate, yIntersectCoordinate);

                        return true;
                    }
                }
                            //}
                //        }
                //    }
                //}
            }

            intersection = null;
            intersectionCoordinates = new Point();
            return false;
        }

Usage Example

Esempio n. 1
0
        public bool TriangulateClosestEndPoint(ILineSegment intersectingLineSegment, out Point closestPoint)
        {
            ILineSegment pointASegment = new LineSegment(intersectingLineSegment.PointA, TriangulationPoint);
            ILineSegment pointBSegment = new LineSegment(intersectingLineSegment.PointB, TriangulationPoint);

            IntersectionDetector detector = new IntersectionDetector();

            detector.Add(pointASegment);
            detector.Add(pointBSegment);

            ILineSegment closestSegment;
            Point        closestSegmentIntersectionPoint;

            ILineSegment segment = new LineSegment(this.PointA, this.PointB, this.TriangulationPoint, true);

            if (detector.FindIntersection(segment, out closestSegment, out closestSegmentIntersectionPoint))
            {
                closestPoint = closestSegment.PointA;

                return(true);
            }
            else
            {
                closestPoint = new Point(0, 0);

                return(false);
            }
        }
All Usage Examples Of SilverlightMappingToolBasic.IntersectionDetector::FindIntersection