示例#1
0
        public static Point Centroid(this IElement2D element2D)
        {
            Point  tmp  = Geometry.Query.Centroid(element2D.OutlineCurve());
            double area = Geometry.Query.Area(element2D.OutlineCurve());

            double x = tmp.X * area;
            double y = tmp.Y * area;
            double z = tmp.Z * area;


            List <PolyCurve> openings = Geometry.Compute.BooleanUnion(element2D.InternalOutlineCurves());

            foreach (ICurve o in openings)
            {
                Point  oTmp  = Geometry.Query.ICentroid(o);
                double oArea = o.IArea();
                x    -= oTmp.X * oArea;
                y    -= oTmp.Y * oArea;
                z    -= oTmp.Z * oArea;
                area -= oArea;
            }

            return(new Point {
                X = x / area, Y = y / area, Z = z / area
            });
        }
示例#2
0
        public static List <ICurve> ElementCurves(this IElement2D element2D, bool recursive = true)
        {
            List <ICurve> result = new List <ICurve>();

            PolyCurve outline = element2D.OutlineCurve();

            foreach (ICurve curve in outline.Curves)
            {
                if (recursive)
                {
                    result.AddRange(curve.ISubParts());
                }
                else
                {
                    result.Add(curve);
                }
            }

            foreach (IElement2D e in element2D.IInternalElements2D())
            {
                result.AddRange(e.ElementCurves(recursive));
            }

            return(result);
        }
        public static List <Point> ElementVertices(this IElement2D element2D)
        {
            List <Point> result = new List <Point>();

            result.AddRange(element2D.OutlineCurve().ElementVertices());
            foreach (IElement2D e in element2D.IInternalElements2D())
            {
                result.AddRange(e.ElementVertices());
            }

            return(result);
        }
示例#4
0
        public static List <Point> ControlPoints(this IElement2D element2D, bool externalOnly = false)
        {
            List <Point> pts = Geometry.Query.ControlPoints(element2D.OutlineCurve());

            if (!externalOnly)
            {
                foreach (IElement2D e in element2D.IInternalElements2D())
                {
                    pts.AddRange(e.ControlPoints());
                }
            }
            return(pts);
        }
示例#5
0
        public static double Area(this IElement2D element2D)
        {
            double result = element2D.OutlineCurve().IArea();

            List <PolyCurve> openings = element2D.InternalOutlineCurves().BooleanUnion();

            foreach (PolyCurve o in openings)
            {
                result -= o.Area();
            }

            return(result);
        }
示例#6
0
        public static double Area(this IElement2D element2D)
        {
            double result = BH.Engine.Geometry.Query.Area(element2D.OutlineCurve());

            List <PolyCurve> openings = element2D.InternalOutlineCurves().BooleanUnion();

            foreach (PolyCurve o in openings)
            {
                result -= BH.Engine.Geometry.Query.Area(o);
            }

            return(result);
        }
示例#7
0
        public static Plane FitPlane(this IElement2D element2D, bool externalOnly = false, double tolerance = Tolerance.Distance)
        {
            List <Point> controlPoints = element2D.OutlineCurve().ControlPoints();

            if (!externalOnly)
            {
                foreach (PolyCurve internalOutline in element2D.InternalOutlineCurves())
                {
                    controlPoints.AddRange(internalOutline.ControlPoints());
                }
            }

            return(controlPoints.FitPlane(tolerance));
        }
        public static bool IsSelfIntersecting(this IElement2D element2D, double tolerance = Tolerance.Distance)
        {
            if (Geometry.Query.IIsSelfIntersecting(element2D.OutlineCurve(), tolerance))
            {
                return(true);
            }

            foreach (PolyCurve internalOutline in element2D.InternalOutlineCurves())
            {
                if (Geometry.Query.IIsSelfIntersecting(internalOutline, tolerance))
                {
                    return(true);
                }
            }

            return(false);
        }
示例#9
0
        public static IElement2D RoundCoordinates(this IElement2D element2d, int decimalPlaces = 6)
        {
            Vector normal = element2d.Normal().Normalise();

            if (Math.Abs(Math.Abs(normal.X) - 1) < Tolerance.Angle ||
                Math.Abs(Math.Abs(normal.Y) - 1) < Tolerance.Angle ||
                Math.Abs(Math.Abs(normal.Z) - 1) < Tolerance.Angle)
            {
                Plane plane = new Plane()
                {
                    Origin = Geometry.Modify.RoundCoordinates(element2d.OutlineCurve().StartPoint(), decimalPlaces), Normal = normal.RoundCoordinates(0)
                };

                element2d = element2d.ISetOutlineElements1D(element2d.IOutlineElements1D().Select(x => x.ISetGeometry(Geometry.Modify.IRoundCoordinates(x.IGeometry().IProject(plane), decimalPlaces))).ToList());

                return(element2d.ISetInternalElements2D(element2d.IInternalElements2D().Select(y => y.ISetOutlineElements1D(y.IOutlineElements1D().Select(x => x.ISetGeometry(Geometry.Modify.IRoundCoordinates(x.IGeometry().IProject(plane), decimalPlaces))).ToList())).ToList()));
            }

            Reflection.Compute.RecordWarning("Rounding the coordinates of a planar surface that is not aligned with the global coordinate system cannot be achieved without risk of losing planarity. No action has been taken.");
            return(element2d);
        }
示例#10
0
        public static IElement2D RoundCoordinates(this IElement2D element2d, int decimalPlaces = 6)
        {
            bool planar = element2d.IIsPlanar();

            if (planar)
            {
                Vector normal = element2d.FitPlane().Normal.Normalise();

                //If the element is planar AND aligned with one of the main coordinate system's planes then rounded element will get projected on this plane to keep it's planarity.
                if (Math.Abs(Math.Abs(normal.X) - 1) < Tolerance.Angle ||
                    Math.Abs(Math.Abs(normal.Y) - 1) < Tolerance.Angle ||
                    Math.Abs(Math.Abs(normal.Z) - 1) < Tolerance.Angle)
                {
                    Plane plane = new Plane()
                    {
                        Origin = Geometry.Modify.RoundCoordinates(element2d.OutlineCurve().StartPoint(), decimalPlaces), Normal = normal.RoundCoordinates(0)
                    };

                    element2d = element2d.ISetOutlineElements1D(element2d.IOutlineElements1D().Select(x => x.ISetGeometry(Geometry.Modify.IRoundCoordinates(x.IGeometry().IProject(plane), decimalPlaces))).ToList());

                    return(element2d.ISetInternalElements2D(element2d.IInternalElements2D().Select(y => y.ISetOutlineElements1D(y.IOutlineElements1D().Select(x => x.ISetGeometry(Geometry.Modify.IRoundCoordinates(x.IGeometry().IProject(plane), decimalPlaces))).ToList())).ToList()));
                }
            }

            //Here is the part with the default way of rounding element's coordinates:

            IElement2D newElement2d = element2d.ISetOutlineElements1D(element2d.IOutlineElements1D().Select(x => x.ISetGeometry(Geometry.Modify.IRoundCoordinates(x.IGeometry(), decimalPlaces))).ToList());

            newElement2d = newElement2d.ISetInternalElements2D(newElement2d.IInternalElements2D().Select(y => y.ISetOutlineElements1D(y.IOutlineElements1D().Select(x => x.ISetGeometry(Geometry.Modify.IRoundCoordinates(x.IGeometry(), decimalPlaces))).ToList())).ToList());

            if (planar && !newElement2d.IsPlanar()) //If the original element was planar we need to ensure that result is planar as well.
            {
                Reflection.Compute.RecordWarning("Rounding the coordinates of an IElement2D couldn't be achieved without losing planarity. No action has been taken.");
                return(element2d);
            }

            return(newElement2d);
        }
示例#11
0
        public static List <IElement2D> AdjacentElements(this IElement2D element, IEnumerable <IElement2D> referenceElements)
        {
            List <IElement2D> adjacentElements = new List <IElement2D>();

            if (element == null || referenceElements == null)
            {
                Reflection.Compute.RecordWarning("Can not get adjacencies of a null element.");
                return(null);
            }

            PolyCurve outline = element.OutlineCurve();

            foreach (IElement2D refElem in referenceElements)
            {
                PolyCurve refOutline = refElem.OutlineCurve();
                if (refOutline.IIsAdjacent(outline))
                {
                    adjacentElements.Add(refElem);
                }
            }

            return(adjacentElements);
        }
示例#12
0
 public static Point Centroid(this IElement2D element2D, double tolerance = Tolerance.Distance)
 {
     return(Geometry.Query.Centroid(new List <ICurve> {
         element2D.OutlineCurve()
     }, element2D.InternalOutlineCurves(), tolerance));
 }
示例#13
0
 public static Vector Normal(this IElement2D element2D)
 {
     return(element2D.OutlineCurve().Normal());
 }