예제 #1
0
        public static BH.oM.Geometry.Vector DominantVector(this IElement2D element2D, bool orthogonalPriority = true, double orthogonalLengthFactor = 0.5, double angleTolerance = BH.oM.Geometry.Tolerance.Angle)
        {
            if (element2D == null || orthogonalPriority == null || orthogonalLengthFactor == null || angleTolerance == null)
            {
                BH.Engine.Reflection.Compute.RecordError("One or more of the inputs is empty or null.");
                return(null);
            }

            IElement1D outline = BH.Engine.Geometry.Create.PolyCurve(element2D.IOutlineElements1D().Select(x => x.IGeometry()));

            return(DominantVector(outline, orthogonalPriority, orthogonalLengthFactor, angleTolerance));
        }
예제 #2
0
        public static bool IsNearGrid(this IElement2D element2D, Grid grid, double maxDistance)
        {
            List <IElement1D> elements1D = element2D.IOutlineElements1D();

            foreach (IElement1D e1D in elements1D)
            {
                if (IsNearGrid(e1D, grid, maxDistance))
                {
                    return(true);
                }
            }
            return(false);
        }
예제 #3
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);
        }
예제 #4
0
        public static bool IsNearLevel(this IElement2D element2D, Level level, double maxDistance)
        {
            List <IElement1D> elements1D = element2D.IOutlineElements1D();

            foreach (IElement1D e1D in elements1D)
            {
                if (IsNearLevel(e1D, level, maxDistance))
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #5
0
        /***************************************************/
        /**** Public Methods - IElements                ****/
        /***************************************************/

        public static IElement2D Translate(this IElement2D element2D, Vector transform) //todo: move this to analytical along with other IElement methods
        {
            List <IElement1D> newOutline = new List <IElement1D>();

            foreach (IElement1D element1D in element2D.IOutlineElements1D())
            {
                newOutline.Add(element1D.Translate(transform));
            }
            IElement2D result = element2D.ISetOutlineElements1D(newOutline);

            List <IElement2D> newInternalOutlines = new List <IElement2D>();

            foreach (IElement2D internalElement2D in result.IInternalElements2D())
            {
                newInternalOutlines.Add(internalElement2D.Translate(transform));
            }
            result = result.ISetInternalElements2D(newInternalOutlines);
            return(result);
        }
예제 #6
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);
        }
예제 #7
0
        /***************************************************/
        /**** Private Methods - IElements               ****/
        /***************************************************/

        private static IElement2D Transform(this IElement2D element2D, TransformMatrix transform, double tolerance)
        {
            if (!transform.IsRigidTransformation(tolerance))
            {
                BH.Engine.Reflection.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported.");
                return null;
            }

            List<IElement1D> newOutline = new List<IElement1D>();
            foreach (IElement1D element1D in element2D.IOutlineElements1D())
            {
                newOutline.Add(element1D.Transform(transform, tolerance));
            }
            IElement2D result = element2D.ISetOutlineElements1D(newOutline);

            List<IElement2D> newInternalOutlines = new List<IElement2D>();
            foreach (IElement2D internalElement2D in result.IInternalElements2D())
            {
                newInternalOutlines.Add(internalElement2D.Transform(transform, tolerance));
            }
            result = result.ISetInternalElements2D(newInternalOutlines);
            return result;
        }
예제 #8
0
        /******************************************/
        /****            IElement2D            ****/
        /******************************************/

        public static PolyCurve IOutlineCurve(this IElement2D element2D)
        {
            return(new PolyCurve {
                Curves = element2D.IOutlineElements1D().Select(e => e.IGeometry()).ToList()
            });
        }