public PolygonIntersection FindIntersectionPolygon( IParametricSurface firstSurface, IParametricSurface secondSurface, Point3D intersectionNearPoint ) { _surfaces[0] = firstSurface; _surfaces[1] = secondSurface; var firstGuessParametrisation = NearestPointFinder.FindNearest( _surfaces[0], intersectionNearPoint ); var secondGuessParametrisation = NearestPointFinder.FindNearest( _surfaces[1], intersectionNearPoint ); firstGuessParametrisation.Boundaries = firstSurface.ParametrisationBoundaries; secondGuessParametrisation.Boundaries = secondSurface.ParametrisationBoundaries; var trackingDistanceSetting = TrackingDistance; TrackingDistance = -trackingDistanceSetting; var polygonPart = GetDirectionalPolygonPart( firstGuessParametrisation, secondGuessParametrisation ); if (polygonPart.IsLooped) { return(polygonPart); } TrackingDistance = trackingDistanceSetting; var polygonRemainingPart = GetDirectionalPolygonPart( firstGuessParametrisation, secondGuessParametrisation ); if (polygonRemainingPart.IsLooped) { return(polygonRemainingPart); } return(PolygonIntersection.JoinFromSamePoint( polygonPart, polygonRemainingPart )); }
private PolygonIntersection GetDirectionalPolygonPart( Parametrisation firstGuessParametrisation, Parametrisation secondGuessParametrisation ) { IntersectionParametrisation?previousParametrisation = null; var currentIntersectionParametrisation = FindFirstIntersection( firstGuessParametrisation, secondGuessParametrisation ); var polygon = new PolygonIntersection(); polygon.EqualityEpsilon = 0.001; while (currentIntersectionParametrisation.HasValue && !AreEdgeTrackingBoundaryConditionsFullfilled( previousParametrisation, currentIntersectionParametrisation ) ) { if (polygon.FinishIfLoopedBack( currentIntersectionParametrisation.Value )) { break; } polygon.Add(currentIntersectionParametrisation.Value); var nextGuess = GetNextInitialGuess( currentIntersectionParametrisation.Value ); if (!nextGuess.HasValue) { break; } previousParametrisation = currentIntersectionParametrisation; currentIntersectionParametrisation = FindFirstIntersection( nextGuess.Value.First, nextGuess.Value.Second ); } return(polygon); }
public static PolygonIntersection JoinFromSamePoint( PolygonIntersection left, PolygonIntersection right ) { var rightSegment = right.Polygon.ToList(); rightSegment.Reverse(); var intersection = new PolygonIntersection { Polygon = rightSegment.Concat(left.Polygon).ToList() }; return(intersection); }