コード例 #1
0
        /// <summary>
        /// True if (a) both polygons lie in the same plane (vertical distance up to Msystem.Tolerance), and
        /// (b) they overlap (the overlapping horizontal distance exceeds Msystem.Tolerance)
        /// </summary>
        public bool OverlapsWith(Polygon3D another)
        {
            if (!(Normal.IsParallelTo(another.Normal) &&
                  Plane.AbsoluteDistanceTo(another[0]) < MSystem.Tolerance))
            {
                return(false);
            }

            // If one polygon contains inside a vertex of another, then they overlap
            // Border tolerance is allowed for case that they just touch (do not overlap)
            if (another.Any(t => ContainsPoint(t, MSystem.Tolerance)) ||
                this.Any(t => another.ContainsPoint(t, MSystem.Tolerance)))
            {
                return(true);
            }

            // Now check the case when no vertex of one polygon lies inside another
            var intersections = new HashSet <Point3D>();

            foreach (var edge1 in Edges)
            {
                foreach (var edge2 in another.Edges)
                {
                    var intersection = edge1.ClosestPointsBetween(edge2, true);
                    if (intersection.Item1.DistanceTo(intersection.Item2) < MSystem.Tolerance)
                    {
                        intersections.Add(intersection.Item1);
                    }
                }
            }
            if (!intersections.Any())
            {
                return(false);
            }

            // Again exclude the case when they just touch and do not overlap
            var c = Point3D.Centroid(intersections);

            return(ContainsPoint(c, MSystem.Tolerance) || another.ContainsPoint(c, MSystem.Tolerance));
        }
コード例 #2
0
 public double AbsoluteDistanceToPoint3D()
 {
     return(Plane1.AbsoluteDistanceTo(Point3D));
 }