public static CompositeGeometry Layout(this ConcreteSection property, double xStart = 0, double xEnd = 1) { CompositeGeometry geometry = new CompositeGeometry(); foreach (Reinforcement reo in property.Reinforcement) { CompositeGeometry layout = reo.ILayout(property); foreach (IGeometry obj in layout.Elements) { if (obj is Point) { geometry.Elements.Add(new Circle { Centre = obj as Point, Normal = Vector.ZAxis, Radius = reo.Diameter / 2 }); } else { geometry.Elements.Add(obj); } } } return(geometry); }
public static IGeometry GeometricalRepresentation(this Panel panel, RepresentationOptions reprOptions = null) { if (panel == null) { BH.Engine.Base.Compute.RecordError("Cannot compute the geometrical representation of a null Structural Panel."); return(null); } reprOptions = reprOptions ?? new RepresentationOptions(); PlanarSurface centralPlanarSurface = Engine.Geometry.Create.PlanarSurface( Engine.Geometry.Compute.IJoin(panel.ExternalEdges.Select(x => x.Curve).ToList()).FirstOrDefault(), panel.Openings.SelectMany(x => Engine.Geometry.Compute.IJoin(x.Edges.Select(y => y.Curve).ToList())).Cast <ICurve>().ToList()); if (!reprOptions.Detailed2DElements) //simple representation { return(centralPlanarSurface); } else { CompositeGeometry compositeGeometry = new CompositeGeometry(); double thickness = panel.Property.IAverageThickness(); Vector translateVect = new Vector() { Z = -thickness / 2 }; Vector extrudeVect = new Vector() { Z = thickness }; Vector upHalf = new Vector() { X = 0, Y = 0, Z = thickness / 2 }; Vector downHalf = new Vector() { X = 0, Y = 0, Z = -thickness / 2 }; PlanarSurface topSrf = centralPlanarSurface.ITranslate(upHalf) as PlanarSurface; PlanarSurface botSrf = centralPlanarSurface.ITranslate(downHalf) as PlanarSurface; IEnumerable <ICurve> internalEdgesBot = panel.InternalElementCurves().Select(c => c.ITranslate(translateVect)); IEnumerable <Extrusion> internalEdgesExtrusions = internalEdgesBot.Select(c => BH.Engine.Geometry.Create.Extrusion(c, extrudeVect)); IEnumerable <ICurve> externalEdgesBot = panel.ExternalEdges.Select(c => c.Curve.ITranslate(translateVect)); IEnumerable <Extrusion> externalEdgesExtrusions = externalEdgesBot.Select(c => BH.Engine.Geometry.Create.Extrusion(c, extrudeVect)); compositeGeometry.Elements.Add(topSrf); compositeGeometry.Elements.Add(botSrf); compositeGeometry.Elements.AddRange(internalEdgesExtrusions); compositeGeometry.Elements.AddRange(externalEdgesExtrusions); return(compositeGeometry); } }
public static IGeometry Geometry3D(this Panel panel, bool onlyCentralSurface = false) { if (panel.IsNull()) { return(null); } PlanarSurface centralPlanarSurface = Engine.Geometry.Create.PlanarSurface( Engine.Geometry.Compute.IJoin(panel.ExternalEdges.Select(x => x.Curve).ToList()).FirstOrDefault(), panel.Openings.SelectMany(x => Engine.Geometry.Compute.IJoin(x.Edges.Select(y => y.Curve).ToList())).Cast <ICurve>().ToList()); if (onlyCentralSurface) { return(centralPlanarSurface); } else { CompositeGeometry compositeGeometry = new CompositeGeometry(); double thickness = panel.Property.IAverageThickness(); Vector translateVect = new Vector() { Z = -thickness / 2 }; Vector extrudeVect = new Vector() { Z = thickness }; Vector upHalf = new Vector() { X = 0, Y = 0, Z = thickness / 2 }; Vector downHalf = new Vector() { X = 0, Y = 0, Z = -thickness / 2 }; PlanarSurface topSrf = centralPlanarSurface.ITranslate(upHalf) as PlanarSurface; PlanarSurface botSrf = centralPlanarSurface.ITranslate(downHalf) as PlanarSurface; IEnumerable <ICurve> internalEdgesBot = panel.InternalElementCurves().Select(c => c.ITranslate(translateVect)); IEnumerable <Extrusion> internalEdgesExtrusions = internalEdgesBot.Select(c => BH.Engine.Geometry.Create.Extrusion(c, extrudeVect)); IEnumerable <ICurve> externalEdgesBot = panel.ExternalEdges.Select(c => c.Curve.ITranslate(translateVect)); IEnumerable <Extrusion> externalEdgesExtrusions = externalEdgesBot.Select(c => BH.Engine.Geometry.Create.Extrusion(c, extrudeVect)); compositeGeometry.Elements.Add(topSrf); compositeGeometry.Elements.Add(botSrf); compositeGeometry.Elements.AddRange(internalEdgesExtrusions); compositeGeometry.Elements.AddRange(externalEdgesExtrusions); return(compositeGeometry); } }
public static List <Point> Points(CompositeGeometry g) { List <Point> points = new List <Point>(); foreach (var geom in g.Elements) { points.AddRange(IPoints(geom)); } return(points); }
/***************************************************/ public static bool IsPlanar(this CompositeGeometry group, double tolerance = Tolerance.Distance) { foreach (IGeometry element in group.Elements) { if (!element.IIsPlanar(tolerance)) { return(false); } } return(true); }
/***************************************************/ public static bool IsInPlane(this CompositeGeometry group, Plane plane, double tolerance = Tolerance.Distance) { foreach (IGeometry g in group.Elements) { if (!g.IIsInPlane(plane, tolerance)) { return(false); } } return(true); }
/***************************************************/ /**** Public Methods - Others ****/ /***************************************************/ public static List <IGeometry> SubParts(this CompositeGeometry group) { List <IGeometry> exploded = new List <IGeometry>(); List <IGeometry> elements = group.Elements; for (int i = 0; i < elements.Count; i++) { exploded.AddRange(elements[i].ISubParts()); } return(exploded); }
internal static global::Topologic.Cluster ClusterByCompositeGeometry(CompositeGeometry bhomCompositeGeometry, double tolerance) { List <global::Topologic.Topology> topologies = new List <global::Topologic.Topology>(); foreach (IGeometry bhomGeometry in bhomCompositeGeometry.Elements) { global::Topologic.Topology topology = Create.TopologyByGeometry(bhomGeometry, tolerance); topologies.Add(topology); } return(ClusterByTopologies(topologies)); }
public static CompositeGeometry Geometry(this ConcreteSection section) { if (section.SectionProfile.Edges.Count == 0) { return(null); } CompositeGeometry geom = Engine.Geometry.Create.CompositeGeometry(section.SectionProfile.Edges); //if(section.Reinforcement != null) //geom.Elements.AddRange(section.Layout().Elements); return(geom); }
/***************************************************/ public static BoundingBox Bounds(this CompositeGeometry group) { List <IGeometry> elements = group.Elements; if (elements.Count == 0) { return(null); } BoundingBox box = elements[0].IBounds(); for (int i = 1; i < elements.Count; i++) { box += elements[i].IBounds(); } return(box); }
/***************************************************/ /**** Public Methods ****/ /***************************************************/ public static IGeometry IGeometry3D(this IObject obj) { if (obj == null) { return(null); } IGeometry geom = Geometry3D(obj as dynamic); CompositeGeometry comp = geom as CompositeGeometry; if (comp != null && comp.Elements.Count == 1) { geom = comp.Elements[0]; } return(geom); }
/***************************************************/ /**** Public Methods - Graphics ****/ /***************************************************/ public static BH.oM.Graphics.RenderMesh RenderMesh(this CompositeGeometry compositeGeometry, RenderMeshOptions renderMeshOptions = null) { if (compositeGeometry == null) { BH.Engine.Base.Compute.RecordError("Cannot compute the mesh of a null composite geometry object."); return(null); } renderMeshOptions = renderMeshOptions ?? new RenderMeshOptions(); List <RenderMesh> renderMeshes = new List <RenderMesh>(); for (int i = 0; i < compositeGeometry.Elements.Count; i++) { renderMeshes.Add(IRenderMesh(compositeGeometry.Elements[i])); } return(BH.Engine.Representation.Compute.JoinRenderMeshes(renderMeshes)); }
public static IGeometry Geometry3D(this Floor floor, bool upwardLayers = false) { if (floor == null) { BH.Engine.Reflection.Compute.RecordError("Cannot query the 3D geometry of a null floor."); return(null); } CompositeGeometry compositeGeometry = new CompositeGeometry(); var layers = (floor.Construction as BH.oM.Physical.Constructions.Construction).Layers; List <IGeometry> geometries = new List <IGeometry>(); double previousCumulativeThickness = 0; foreach (var layer in layers) { IEnumerable <ICurve> externalEdgesBot = floor.Location.Edges(); Vector bottomVec = new Vector() { Z = previousCumulativeThickness }; Vector extrudeVect = new Vector() { Z = layer.Thickness }; List <Extrusion> edgeExtrusions = new List <Extrusion>(); foreach (var edge in externalEdgesBot) { edgeExtrusions.Add(BH.Engine.Geometry.Create.Extrusion(edge.ITranslate(bottomVec), extrudeVect)); } if (edgeExtrusions.Count() == 1) { // To avoid surface duplication, only append the extrusion. geometries.Add(edgeExtrusions[0]); } else { geometries.Add(floor.Location.ITranslate(bottomVec)); geometries.AddRange(edgeExtrusions); geometries.Add(floor.Location.ITranslate(extrudeVect)); } previousCumulativeThickness += layer.Thickness; } if (upwardLayers) { return new CompositeGeometry() { Elements = geometries } } ; Vector translationVec = new Vector() { Z = -previousCumulativeThickness }; // Reverse the order: Floor suface is top surface, layers grow "downwards"; layer[0] is the top one (closest to the surface). List <IGeometry> translated = new List <IGeometry>(); foreach (var elem in geometries) { translated.Add(elem.ITranslate(translationVec)); } translated.Reverse(); return(new CompositeGeometry() { Elements = translated }); }
/***************************************************/ public static CompositeGeometry Clone(this CompositeGeometry group) { return(new CompositeGeometry { Elements = group.Elements.Select(x => x.IClone()).ToList() }); }
public static Point ClosestPoint(this CompositeGeometry group, Point point) { throw new NotImplementedException(); }
/***************************************************/ public static CompositeGeometry Scale(this CompositeGeometry group, Point origin, Vector scaleVector) { TransformMatrix scaleMatrix = Create.ScaleMatrix(origin, scaleVector); return(Transform(group, scaleMatrix)); }
/***************************************************/ public static CompositeGeometry Translate(this CompositeGeometry group, Vector transform) { return(new CompositeGeometry { Elements = group.Elements.Select(x => x.ITranslate(transform)).ToList() }); }
public static IGeometry GeometricalRepresentation(this Node node, RepresentationOptions reprOptions = null, bool isSubObject = false) { if (node == null) { BH.Engine.Base.Compute.RecordError("Cannot compute the geometrical representation of a null node."); return(null); } reprOptions = reprOptions ?? new RepresentationOptions(); if (node.Position == null) { BH.Engine.Base.Compute.RecordError("Specified Node does not have a position defined."); return(null); } if (node.Support == null || !reprOptions.Detailed0DElements) // If there is no support information, or by choice... { return(node.Position); // ...just return the representation for the point. } // -------------------------------------------- // // -------- Compute the representation -------- // // -------------------------------------------- // // Design different representations for different DOF type. // For now, all the following DOFTypes are considered "fixed". More, differentiated representations can be added later DOFType[] fixedDOFTypes = new[] { DOFType.Fixed, DOFType.FixedNegative, DOFType.FixedPositive, DOFType.Spring, DOFType.Friction, DOFType.Damped, DOFType.SpringPositive, DOFType.SpringNegative }; bool fixedToTranslation = fixedDOFTypes.Contains(node.Support.TranslationX) || fixedDOFTypes.Contains(node.Support.TranslationY) || fixedDOFTypes.Contains(node.Support.TranslationZ); bool fixedToRotation = fixedDOFTypes.Contains(node.Support.RotationX) || fixedDOFTypes.Contains(node.Support.RotationY) || fixedDOFTypes.Contains(node.Support.RotationZ); if (fixedToTranslation && fixedToRotation) { // Fully fixed: box double boxDims = 0.2 * reprOptions.Element0DScale; var centrePoint = node.Position; BoundingBox bbox = BH.Engine.Geometry.Create.BoundingBox( new Point() { X = centrePoint.X + 2 * boxDims, Y = centrePoint.Y + 2 * boxDims, Z = centrePoint.Z + boxDims * 1.5 }, new Point() { X = centrePoint.X - 2 * boxDims, Y = centrePoint.Y - 2 * boxDims, Z = centrePoint.Z - boxDims * 1.5 }); return(bbox); } if (fixedToTranslation && !fixedToRotation) { // Pin: cone + sphere double radius = 0.15 * reprOptions.Element0DScale; CompositeGeometry compositeGeometry = new CompositeGeometry(); Sphere sphere = BH.Engine.Geometry.Create.Sphere(node.Position, radius); compositeGeometry.Elements.Add(sphere); double coneHeight = 4 * radius; Cone cone = BH.Engine.Geometry.Create.Cone( new Point() { X = node.Position.X, Y = node.Position.Y, Z = node.Position.Z - radius / 2 - coneHeight }, new Vector() { X = 0, Y = 0, Z = 1 }, 3 * radius, coneHeight ); compositeGeometry.Elements.Add(cone); return(compositeGeometry); } // Else: we could add more for other DOFs; for now just return the representation for its point. if (!isSubObject) { return(node.Position.GeometricalRepresentation(reprOptions)); } else { return(null); //do not return representation for point if the Nodes are sub-objects (e.g. of a bar) } }
/***************************************************/ public static bool IsEqual(this CompositeGeometry group, CompositeGeometry other, double tolerance = Tolerance.Distance) { return(group.Elements.Count == other.Elements.Count && group.Elements.Zip(other.Elements, (a, b) => a.IIsEqual(b, tolerance)).All(x => x)); }
/***************************************************/ public static CompositeGeometry Rotate(this CompositeGeometry group, Point origin, Vector axis, double rad) { TransformMatrix rotationMatrix = Create.RotationMatrix(origin, axis, rad); return(Transform(group, rotationMatrix)); }
/***************************************************/ public static CompositeGeometry Project(this CompositeGeometry group, Plane p) { return(new CompositeGeometry { Elements = group.Elements.Select(x => x.IProject(p)).ToList() }); }
/***************************************************/ public static CompositeGeometry ProjectAlong(this CompositeGeometry group, Plane plane, Vector vector) { return(new CompositeGeometry { Elements = group.Elements.Select(x => x.IProjectAlong(plane, vector)).ToList() }); }