Beispiel #1
0
        private static int GetIntersection(Surface face, List <Surface> surfaces, Point point, double offset, ref List <Curve> curves, bool reverse)
        {
            Surface my = face;

            if (face.GetType() == typeof(PolySurface))
            {
                PolySurface poly = (PolySurface)face;
                foreach (Surface s in poly.Surfaces())
                {
                    UV coords = s.UVParameterAtPoint(point);
                    if (coords != null && coords.U >= 0 && coords.U <= 1 && coords.V >= 0 && coords.V <= 1)
                    {
                        my = s;
                    }
                }
            }

            // Get the Normal at that point
            Vector normal = my.NormalAtPoint(point);



            // Remove Z Value in order to create horizontal normals
            Vector optimizedNormal = (reverse) ? normal.Reverse() : normal;
            // Vector.ByCoordinates(normal.X, normal.Y, 0).Reverse() : Vector.ByCoordinates(normal.X, normal.Y, 0);

            // Get an startpoint offset if it applies
            Point startPoint = point;

            if (offset != 0)
            {
                Line offsetLine = Line.ByStartPointDirectionLength(point, optimizedNormal, offset);
                startPoint = offsetLine.EndPoint;
            }

            // Create an almost endless line
            Line line = Line.ByStartPointDirectionLength(startPoint, optimizedNormal, 100000000);

            // Get intersection points with boundary surfaces
            List <double> intersections = line.Insersection(surfaces);

            // If there are any intersections
            if (intersections.Count > 1)
            {
                // trim the curve into segments if there are gaps or holes
                Curve[] segments = line.ParameterTrimSegments(intersections.ToArray(), false);

                // Walk through trimmed curves and add only those to the return collection
                // which are of a reasonable length
                foreach (Curve segment in segments)
                {
                    //if (segment.Length < 100000)
                    curves.Add(segment);
                }
            }
            else if (intersections.Count == 1)
            {
                Curve[] segments = line.ParameterSplit(intersections[0]);
                curves.Add(segments[0]);
            }

            return(intersections.Count);
        }