Example #1
0
        public static bool IsNearGrid(this IElement1D element1D, Grid grid, double maxDistance)
        {
            ICurve curve     = element1D.IGeometry().IProject(Plane.XY);
            ICurve gridCurve = grid.Curve.IProject(Plane.XY);

            return(curve.Distance(gridCurve) <= maxDistance);
        }
Example #2
0
        public static bool IsNearLevel(this IElement1D element1D, Level level, double maxDistance)
        {
            ICurve      curve = element1D.IGeometry();
            BoundingBox bBox  = curve.IBounds();

            return(bBox.Min.Z - maxDistance <= level.Elevation && level.Elevation <= bBox.Max.Z + maxDistance);
        }
Example #3
0
        public static List <Point> ElementVertices(this IElement1D element1D)
        {
            ICurve curve = element1D.IGeometry();

            List <Point>  vertices = new List <Point>();
            List <ICurve> subParts = curve.ISubParts().ToList();

            if (subParts.Count == 0 || subParts.All(x => x is Circle))
            {
                return(new List <Point>());
            }

            vertices.Add(curve.IStartPoint());
            foreach (ICurve c in subParts)
            {
                List <Point> discPoints = c.IDiscontinuityPoints();
                if (discPoints.Count != 0)
                {
                    vertices.AddRange(discPoints.Skip(1));
                }
            }

            if (curve.IIsClosed())
            {
                vertices.RemoveAt(vertices.Count - 1);
            }

            return(vertices);
        }
Example #4
0
        /***************************************************/

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

            return element1D.ISetGeometry(Geometry.Modify.ITransform(element1D.IGeometry(), transform));
        }
        /******************************************/
        /****            IElement1D            ****/
        /******************************************/

        public static List <Point> ElementVertices(this IElement1D element1D)
        {
            ICurve       curve    = element1D.IGeometry();
            List <Point> vertices = curve.IDiscontinuityPoints();

            if (curve.IIsClosed())
            {
                vertices.RemoveAt(vertices.Count - 1);
            }

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

            List <ICurve> curves = element1D.IGeometry().ISubParts().ToList();

            if (!curves.Any(x => x.IIsLinear()))
            {
                BH.Engine.Reflection.Compute.RecordWarning("Non-linear curves are using an approximate vector between its start and end.");
            }

            List <Vector> vectors = curves.Select(x => (x.IStartPoint() - x.IEndPoint())).ToList();

            //group vectors by direction whilst comparing angle for tolerance
            List <List <Vector> > groupByNormal = GroupSimilarVectorsWithTolerance(vectors, angleTolerance);

            groupByNormal = groupByNormal.OrderByDescending(x => x.Sum(y => y.Length())).ToList();
            List <Vector> largestGlobal = groupByNormal[0];

            Vector dominantVector = largestGlobal[0].Normalise();

            if (!orthogonalPriority)
            {
                return(dominantVector);
            }

            List <Vector> largestOrthogonal = groupByNormal.FirstOrDefault(x => (x.First().IsOrthogonal(angleTolerance)));

            if (largestOrthogonal != null)
            {
                if (largestGlobal.Sum(x => x.Length()) * orthogonalLengthFactor > largestOrthogonal.Sum(x => x.Length()))
                {
                    BH.Engine.Reflection.Compute.RecordWarning("Orthogonal vector was found but didn't pass the length tolerance in relation to the actual non-orthogonal dominant vector. The actual dominant vector is the output.");
                }
                else
                {
                    dominantVector = largestOrthogonal[0].Normalise();
                }
            }

            return(dominantVector);
        }
Example #7
0
 public static BoundingBox Bounds(this IElement1D element1D)
 {
     return(Geometry.Query.IBounds(element1D.IGeometry()));
 }
Example #8
0
 public static List <ICurve> ElementCurves(this IElement1D element1D, bool recursive = true)
 {
     return(new List <ICurve> {
         element1D.IGeometry()
     });
 }
 public static bool IsSelfIntersecting(this IElement1D element1D, double tolerance = Tolerance.Distance)
 {
     return(Geometry.Query.IIsSelfIntersecting(element1D.IGeometry(), tolerance));
 }
Example #10
0
        /***************************************************/

        public static IElement1D Translate(this IElement1D element1D, Vector transform) //todo: move this to analytical along with other IElement methods
        {
            return(element1D.ISetGeometry(Geometry.Modify.ITranslate(element1D.IGeometry(), transform)));
        }
Example #11
0
 public static IElement1D Translate(this IElement1D element1D, Vector transform)
 {
     return(element1D.ISetGeometry(Geometry.Modify.ITranslate(element1D.IGeometry(), transform)));
 }
Example #12
0
 public static List <Point> ControlPoints(this IElement1D element1D)
 {
     return(Geometry.Query.IControlPoints(element1D.IGeometry()));
 }
Example #13
0
 public static IElement1D RoundCoordinates(this IElement1D element1d, int decimalPlaces = 6)
 {
     return(element1d.ISetGeometry(Geometry.Modify.IRoundCoordinates(element1d.IGeometry(), decimalPlaces)));
 }
Example #14
0
        /******************************************/
        /****            IElement1D            ****/
        /******************************************/

        public static double Length(this IElement1D element1D)
        {
            return(element1D.IGeometry().ILength());
        }
Example #15
0
 public static bool IsPlanar(this IElement1D element1D, double tolerance = Tolerance.Distance)
 {
     return(element1D.IGeometry().IIsPlanar(tolerance));
 }