public static bool NormalTowardsSpace(this BHG.Polyline pline, BHE.Space space) { BHG.Point centrePt = pline.Centre(); List <BHG.Point> pts = BH.Engine.Geometry.Query.DiscontinuityPoints(pline); BHG.Plane plane = BH.Engine.Geometry.Create.Plane(pts[0], pts[1], pts[2]); //The polyline can be locally concave. Check if the polyline is clockwise. if (!BH.Engine.Geometry.Query.IsClockwise(pline, plane.Normal)) { plane.Normal = -plane.Normal; } //Move centrepoint along the normal. If inside - flip the panel if (IsContaining(space, centrePt.Translate(plane.Normal))) { return(true); } else { return(false); } /***************************************************/ }
/***************************************************/ public static bool NormalAwayFromSpace(this BHG.Polyline pline, List <BHE.BuildingElement> elementsAsSpace) { List <BHG.Point> centrePtList = new List <BHG.Point>(); BHG.Point centrePt = pline.Centre(); centrePtList.Add(centrePt); if (!pline.IsClosed()) { return(false); //Prevent failures of the clockwise check } List <BHG.Point> pts = BH.Engine.Geometry.Query.DiscontinuityPoints(pline); if (pts.Count < 3) { return(false); //Protection in case there aren't enough points to make a plane } BHG.Plane plane = BH.Engine.Geometry.Create.Plane(pts[0], pts[1], pts[2]); //The polyline can be locally concave. Check if the polyline is clockwise. if (!BH.Engine.Geometry.Query.IsClockwise(pline, plane.Normal)) { plane.Normal = -plane.Normal; } if (!BH.Engine.Geometry.Query.IsContaining(pline, centrePtList, false)) { BHG.Point pointOnLine = BH.Engine.Geometry.Query.ClosestPoint(pline, centrePt); BHG.Vector vector = new BHG.Vector(); if (BH.Engine.Geometry.Query.Distance(pointOnLine, centrePt) > BH.oM.Geometry.Tolerance.MicroDistance) { vector = pointOnLine - centrePt; } else { BHG.Line line = BH.Engine.Geometry.Query.GetLineSegment(pline, pointOnLine); vector = ((line.Start - line.End).Normalise()).CrossProduct(plane.Normal); } centrePt = BH.Engine.Geometry.Modify.Translate(pointOnLine, BH.Engine.Geometry.Modify.Normalise(vector) * 0.001); } //Move centrepoint along the normal. if (BH.Engine.Environment.Query.IsContaining(elementsAsSpace, centrePt.Translate(plane.Normal * 0.01))) { return(false); } else { return(true); } }
public static global::OpenStudio.Surface ToOSM(this BHE.Panel panel, global::OpenStudio.Model modelReference, global::OpenStudio.Space osmSpace, Dictionary <string, global::OpenStudio.Construction> uniqueConstructions, string outsideBoundaryCondition) { Surface osmElement = new Surface(panel.Polyline().ToOSM(), modelReference); osmElement.setName(panel.Name); osmElement.setSpace(osmSpace); if (outsideBoundaryCondition != "") { osmElement.setOutsideBoundaryCondition(outsideBoundaryCondition); } osmElement.setSurfaceType(panel.Type.ToOSMSurfaceType()); osmElement.setConstruction(uniqueConstructions[panel.Construction.UniqueConstructionName()]); BHP.OriginContextFragment envContextProperties = panel.FindFragment <BHP.OriginContextFragment>(typeof(BHP.OriginContextFragment)); //Fix curtain wall if (panel.Type == BHE.PanelType.CurtainWall) { osmElement.setConstruction(uniqueConstructions["CurtainWallReplacementConstruction"]); //No need for construction on a curtain wall as the opening will handle it List <BHG.Polyline> newOpeningBounds = new List <BHG.Polyline>(); if (panel.Openings.Count > 0) { //This surface already has openings - cut them out of the new opening List <BHG.Polyline> refRegion = panel.Openings.Where(y => y.Polyline() != null).ToList().Select(z => z.Polyline()).ToList(); newOpeningBounds.AddRange((panel.Polyline().BooleanDifference(refRegion, 0.01))); } else { newOpeningBounds.Add(panel.Polyline()); } BHE.Opening curtainWallOpening = new BHE.Opening() { Edges = BH.Engine.Geometry.Create.PolyCurve(newOpeningBounds).ICollapseToPolyline(BH.oM.Geometry.Tolerance.Angle).ToEdges() }; //Scale the bounding curve to comply with IDF rules BHG.Polyline crv = curtainWallOpening.Polyline(); curtainWallOpening.Edges = crv.Scale(crv.Centre(), BH.Engine.Geometry.Create.Vector(0.95, 0.95, 0.95)).ToEdges(); curtainWallOpening.Name = panel.Name; BHP.OriginContextFragment curtainWallProperties = new BHP.OriginContextFragment(); if (envContextProperties != null) { curtainWallProperties.ElementID = envContextProperties.ElementID; curtainWallProperties.TypeName = envContextProperties.TypeName; } curtainWallOpening.Type = BHE.OpeningType.CurtainWall; curtainWallOpening.OpeningConstruction = panel.Construction; panel.Openings = new List <BHE.Opening> { curtainWallOpening }; } return(osmElement); }