Пример #1
0
        /// <summary>
        /// Does this ray intersect the provided polygon area?
        /// </summary>
        /// <param name="polygon">The Polygon to intersect with.</param>
        /// <param name="result">The intersection result.</param>
        /// <returns>True if an intersection occurs, otherwise false. If true, check the intersection result for the location of the intersection.</returns>
        public bool Intersects(Polygon polygon, out Vector3 result)
        {
            var plane = new Plane(polygon.Vertices.First(), polygon.Vertices);

            if (Intersects(plane, out Vector3 intersection))
            {
                var transformToPolygon   = new Transform(plane.Origin, plane.Normal);
                var transformFromPolygon = new Transform(transformToPolygon);
                transformFromPolygon.Invert();
                var transformedIntersection  = transformFromPolygon.OfPoint(intersection);
                IEnumerable <Line> curveList = polygon.Segments();
                curveList = curveList.Select(l => l.TransformedLine(transformFromPolygon));

                if (Polygon.Contains(curveList, transformedIntersection, out _))
                {
                    result = intersection;
                    return(true);
                }
            }
            result = default(Vector3);
            return(false);
        }
Пример #2
0
 /// <summary>
 /// Extend this line to its (nearest, by default) intersection with a polygon.
 /// </summary>
 /// <param name="polygon">The polygon to intersect with</param>
 /// <param name="bothSides">Optional — if false, will only extend in the line's direction; if true will extend in both directions.</param>
 /// <param name="extendToFurthest">Optional — if true, will extend line as far as it will go, rather than stopping at the closest intersection.</param>
 public Line ExtendTo(Polygon polygon, bool bothSides = true, bool extendToFurthest = false)
 {
     return(ExtendTo(polygon.Segments(), bothSides, extendToFurthest));
 }
Пример #3
0
 /// <summary>
 /// Extend this line to its (nearest, by default) intersection with a polygon.
 /// </summary>
 /// <param name="polygon">The polygon to intersect with</param>
 /// <param name="bothSides">Optional — if false, will only extend in the line's direction; if true will extend in both directions.</param>
 /// <param name="extendToFurthest">Optional — if true, will extend line as far as it will go, rather than stopping at the closest intersection.</param>
 /// <param name="tolerance">Optional — The amount of tolerance to include in the extension method.</param>
 public Line ExtendTo(Polygon polygon, bool bothSides = true, bool extendToFurthest = false, double tolerance = Vector3.EPSILON)
 {
     return(ExtendTo(polygon.Segments(), bothSides, extendToFurthest, tolerance));
 }