示例#1
0
        public static bool IsPointOccluded(Point3 point, SimpleSurface face, Vector3 direction, double threshold = Constants.DEFAULT_EPS)
        {
            direction = direction.Normalize();
            var inter = SegmentPlaneIntersection(point, direction, face.Outer.First().P1, face.Normal);

            if (inter == null || Vector3.Dot(inter - point, direction) < threshold)
            {
                return(false);
            }
            return(face.IsPointInSurface(inter, true));
        }
示例#2
0
        public static List <DirectedSegment3> FaceIntersection(SimpleSurface f1, SimpleSurface f2, bool includingBorder = false)
        {
            var     res = new List <DirectedSegment3>();
            Vector3 dir;
            Point3  p;
            var     inter = PlaneIntersection(f1.Outer.First().P1, f1.Normal, f2.Outer.First().P1, f2.Normal, out p, out dir);

            if (!inter)
            {
                return(res);
            }
            var segments = new List <DirectedSegment3>();

            segments.AddRange(f1.Outer);
            foreach (var inner in f1.Inners)
            {
                segments.AddRange(inner);
            }
            segments.AddRange(f2.Outer);
            foreach (var inner in f2.Inners)
            {
                segments.AddRange(inner);
            }
            var intersections = new List <Point3>();

            foreach (var segment in segments)
            {
                Point3 intersection;
                inter = LineIntersection(segment.P1, segment.Direction, p, dir, out intersection);
                if (inter)
                {
                    intersections.Add(intersection);
                }
            }
            if (intersections.Count <= 1)
            {
                return(res);
            }
            intersections = SortInLine3(intersections);
            var prev = intersections[0];

            for (var i = 1; i < intersections.Count; i++)
            {
                var current = intersections[i];
                if (f1.IsPointInSurface(prev + (current - prev) / 2, includingBorder) &&
                    f2.IsPointInSurface(prev + (current - prev) / 2, includingBorder))
                {
                    res.Add(new DirectedSegment3(prev, current));
                }
                prev = current;
            }
            return(res);
        }
示例#3
0
        public List <SimpleSurface> DecomposeToSimpleSurfaces()
        {
            var ps  = _outer.SelectMany(edge => edge.Decompose().Select(s => s.P1)).ToList();
            var res = new SimpleSurface(ps);

            foreach (var inner in _inners)
            {
                ps = inner.SelectMany(edge => edge.Decompose().Select(s => s.P1)).ToList();
                res.AddInner(ps);
            }
            return(new List <SimpleSurface> {
                res
            });
        }
示例#4
0
        public static List <DirectedSegment3> Occlude(SimpleSurface surface, DirectedSegment3 segment)
        {
            var segments = surface.Outer.ToList();

            segments.Add(segment);
            var broken = BreakSegmentsBySegments(segments);
            var res    = new List <DirectedSegment3>();

            foreach (var ds in broken)
            {
                if (!Utils.IsPointOccluded(ds.Center, surface, Vector3.Z_AXIS))
                {
                    res.Add(ds);
                }
            }
            return(res);
        }