def CalcRevealDims(_phpp_window_obj, RevealShaderObjs_input, SideIntersectionSurface, Side_OriginPt, Side_Direction): #Test shading objects for their edge points Side_IntersectionCurve = [] Side_IntersectionPoints = [] for i in range(len(RevealShaderObjs_input)): #This is the list of shading objects to filter if ghc.BrepXBrep(RevealShaderObjs_input[i], SideIntersectionSurface).curves != None: Side_IntersectionCurve.append(ghc.BrepXBrep(RevealShaderObjs_input[i], SideIntersectionSurface).curves) for i in range(len(Side_IntersectionCurve)): for k in range(len(ghc.ControlPoints(Side_IntersectionCurve[i]).points)): Side_IntersectionPoints.append(ghc.ControlPoints(Side_IntersectionCurve[i]).points[k]) #Find the top/closets point for each of the objects that could possibly shade Side_KeyPoints = [] Side_Rays = [] Side_Angles = [] for i in range(len(Side_IntersectionPoints)): if Side_OriginPt != Side_IntersectionPoints[i]: Ray = ghc.Vector2Pt(Side_OriginPt, Side_IntersectionPoints[i], False).vector Angle = math.degrees(ghc.Angle(_phpp_window_obj.surface_normal, Ray).angle) if Angle < 89.9: Side_Rays.append(Ray) Side_Angles.append(float(Angle)) Side_KeyPoints.append(Side_IntersectionPoints[i]) Side_KeyPoint = Side_KeyPoints[Side_Angles.index(min(Side_Angles))] Side_KeyRay = Side_Rays[Side_Angles.index(min(Side_Angles))] #use the Key point found to calculte the Distances for the PHPP Shading Calculator Side_Hypot = ghc.Length(ghc.Line(Side_OriginPt, Side_KeyPoint)) Deg = (ghc.Angle(Side_Direction, Side_KeyRay).angle) #note this is in Radians Side_o_reveal = math.sin(Deg) * Side_Hypot Side_d_reveal = math.sqrt(Side_Hypot**2 - Side_o_reveal**2) Side_CheckLine = ghc.Line(Side_OriginPt, Side_KeyPoint) return [Side_o_reveal, Side_d_reveal, Side_CheckLine]
def _get_verts(obj): brp_edges = ghc.DeconstructBrep(obj).edges brp_perim = ghc.JoinCurves(brp_edges, True) brp_verts = ghc.ControlPoints(brp_perim).points brpC = ghc.CullDuplicates(brp_verts, 0.0).points verts = (ev.from_Rh_points(vert) for vert in brpC) #brp_verts return list(verts)
def getIDFWindowObjects(_IDF_Objs, _windowConstructionsSimple, _windowMaterialsSimple): # Finds all the widnow surfaces and builds window objects windowSurfaces = [] windowObjs_raw = [] windowObjs_filtered = [] windowObjs_triangulated = {} for eachIDFobj in _IDF_Objs: try: idfObjName = getattr(eachIDFobj, 'objName') except: idfObjName = '' # If its an EP Window Object if 'FenestrationSurface:Detailed' in idfObjName: windowObjs_raw.append(eachIDFobj) ################################################## # Fix for window triangulation for windowObj in windowObjs_raw: # Honeybee adds the code '..._glzP_0, ..._glzP_1, etc..' suffix to the name for its triangulated windows if '_glzP_' in windowObj.Name: # See if it has only 3 vertices as well just to double check numOfVerts = 0 for key in windowObj.__dict__.keys(): if 'XYZ Vertex' in key: numOfVerts += 1 if numOfVerts == 3: # Ok, so its a triangulated window. # File the triangulated window in the dictionary using its name as key tempWindowName = windowObj.Name.split('_glzP_')[0] if tempWindowName not in windowObjs_triangulated.keys(): windowObjs_triangulated[tempWindowName] = [windowObj] else: windowObjs_triangulated[tempWindowName].append(windowObj) else: windowObjs_filtered.append(windowObj) else: windowObjs_filtered.append(windowObj) # Unite the triangulated objects for key in windowObjs_triangulated.keys(): perims = [] for windowObj in windowObjs_triangulated[key]: triangleVerts = [] # Get the verts for key in windowObj.__dict__.keys(): if 'XYZ Vertex' in key: verts = getattr(windowObj, key).split(' ') verts = [float(x) for x in verts] point = ghc.ConstructPoint(verts[0], verts[1], verts[2]) triangleVerts.append(point) # Union the Segments, find the outside perimeter perim = ghc.PolyLine(triangleVerts, closed=True) perims.append(perim) unionedPerim = ghc.RegionUnion(perims) # Build a new Window Obj using this now unioned geometry newVertPoints = ghc.ControlPoints( unionedPerim).points #windowObj.__dict__ newWindowObj = copy.deepcopy(windowObj) for i in range(len(newVertPoints)): setattr(newWindowObj, 'XYZ Vertex {} {}'.format(i + 1, '{m}'), str(newVertPoints[i]).replace(',', ' ')) setattr(newWindowObj, 'Name', windowObj.Name[:-7]) windowObjs_filtered.append(newWindowObj) ################################################## # Build the Window Objects for eachWindowObj in windowObjs_filtered: # Find the windows's CONSTRUCTION and MATERIAL information in the IDF thisWindowEP_CONST_Name = getattr( eachWindowObj, 'Construction Name') # Get the name of the Windows' Construction thisWindowEP_MAT_Name = _windowConstructionsSimple[ thisWindowEP_CONST_Name].Layers[0][ 1] # Find the Material name of 'Layer 1' in the Window's Construction thisWindowEP_WinSimp_Obj = _windowMaterialsSimple[ thisWindowEP_MAT_Name] # Find the 'WindowMaterial:SimpleGlazingSystem' Object with the same name as 'Layer 1' winterShadingFactor = 0.75 summerShadingFactor = 0.75 # Create the new IDF_Obj_surfaceWindow Object windowSurfaces.append( IDF_Obj_surfaceWindow(eachWindowObj, thisWindowEP_WinSimp_Obj, winterShadingFactor, summerShadingFactor)) return windowSurfaces
def find_overhang_shading(_phpp_window_obj, _shadingGeom, _extents=99): # Figure out the glass surface (inset a bit) and then # find the origin point for all the subsequent shading calcs (top, middle) glzgCenter = ghc.Area(_phpp_window_obj.glazing_surface).centroid glazingEdges = _phpp_window_obj._get_edges_in_order( _phpp_window_obj.glazing_surface ) glazingTopEdge = from_linesegment3d(glazingEdges.Top) ShadingOrigin = ghc.CurveMiddle(glazingTopEdge) # In order to also work for windows which are not vertical, find the # 'direction' from the glazing origin and the top/middle ege point UpVector = ghc.Vector2Pt(glzgCenter, ShadingOrigin, True).vector #----------------------------------------------------------------------- # First, need to filter the scene to find the objects that are 'above' # the window. Create a 'test plane' that is _extents (99m) tall and 0.5m past the wall surface, test if # any objects intersect that plane. If so, add them to the set of things # test in the next step depth = float(_phpp_window_obj.install_depth) + 0.5 edge1 = ghc.LineSDL(ShadingOrigin, UpVector, _extents) edge2 = ghc.LineSDL(ShadingOrigin, _phpp_window_obj.surface_normal, depth) intersectionTestPlane = ghc.SumSurface(edge1, edge2) OverhangShadingObjs = (x for x in _shadingGeom if ghc.BrepXBrep(intersectionTestPlane, x).curves != None) #----------------------------------------------------------------------- # Using the filtered set of shading objects, find the 'edges' of shading # geom and then decide where the maximums shading point is # Create a new 'test' plane coming off the origin (99m in both directions this time). # Test to find any intersection shading objs and all their crvs/points with this plane HorizontalLine = ghc.LineSDL(ShadingOrigin, _phpp_window_obj.surface_normal, _extents) VerticalLine = ghc.LineSDL(ShadingOrigin, UpVector, _extents) IntersectionSurface = ghc.SumSurface(HorizontalLine, VerticalLine) IntersectionCurves = (ghc.BrepXBrep(obj, IntersectionSurface).curves for obj in OverhangShadingObjs if ghc.BrepXBrep(obj, IntersectionSurface).curves != None) IntersectionPointsList = (ghc.ControlPoints(crv).points for crv in IntersectionCurves) IntersectionPoints = (pt for list_of_pts in IntersectionPointsList for pt in list_of_pts) #----------------------------------------------------------------------- # If there are any intersection Points found, choose the right one to use to calc shading.... # Find the top/closets point for each of the objects that could possibly shade smallest_angle_found = 2 * math.pi key_point = None for pt in IntersectionPoints: if pt == None: continue # Protect against Zero-Length error ray = ghc.Vector2Pt(ShadingOrigin, pt, False).vector if ray.Length < 0.001: continue this_ray_angle = ghc.Angle(_phpp_window_obj.surface_normal , ray).angle if this_ray_angle < 0.001: continue if this_ray_angle <= smallest_angle_found: smallest_angle_found = this_ray_angle key_point = pt #----------------------------------------------------------------------- # Use the 'key point' found to deliver the Height and Distance for the PHPP Shading Calculator if not key_point: d_over = None o_over = None CheckLine = VerticalLine else: d_over = key_point.Z - ShadingOrigin.Z # Vertical distance Hypot = ghc.Length(ghc.Line(ShadingOrigin, key_point)) # Hypot o_over = math.sqrt(Hypot**2 - d_over**2) # Horizontal distance CheckLine = ghc.Line(ShadingOrigin, key_point) return d_over, o_over, CheckLine
def find_horizon_shading(_phpp_window_obj, _shadingGeom, _extents=99): """ Arguments: _phpp_winddow_obj: The PHPP_Window object to calcualte the values for _shadingGeom: (list) A list of possible shading objects to test against _extents: (float) A number (m) to limit the shading search to. Default = 99m Returns: h_hori: Distance (m) out from the glazing surface of any horizontal shading objects found d_hori: Distance (m) up from the base of the window to the top of any horizontal shading objects found """ surface_normal = _phpp_window_obj.surface_normal #----------------------------------------------------------------------- # Find Starting Point glazingEdges = _phpp_window_obj._get_edges_in_order( _phpp_window_obj.glazing_surface ) glazingBottomEdge = glazingEdges.Bottom ShadingOrigin = ghc.CurveMiddle( from_linesegment3d(glazingBottomEdge) ) UpVector = ghc.VectorXYZ(0,0,1).vector #----------------------------------------------------------------------- # Find if there are any shading objects and if so put them in a list HorizonShading = [] HorizontalLine = ghc.LineSDL(ShadingOrigin, surface_normal, _extents) VerticalLine = ghc.LineSDL(ShadingOrigin, UpVector, _extents) for shadingObj in _shadingGeom: if ghc.BrepXCurve(shadingObj, HorizontalLine).points != None: HorizonShading.append( shadingObj ) #----------------------------------------------------------------------- # Find any intersection Curves with the shading objects IntersectionSurface = ghc.SumSurface(HorizontalLine, VerticalLine) IntersectionCurve = [] IntersectionPoints = [] for shadingObj in HorizonShading: if ghc.BrepXBrep(shadingObj, IntersectionSurface).curves != None: IntersectionCurve.append(ghc.BrepXBrep(shadingObj, IntersectionSurface)) for pnt in IntersectionCurve: IntersectionPoints.append(ghc.ControlPoints(pnt).points) #----------------------------------------------------------------------- # Run the "Top-Corner-Finder" if there are any intersecting objects... if len(IntersectionPoints) != 0: # Find the top/closets point for each of the objects that could possibly shade KeyPoints = [] for pnt in IntersectionPoints: Rays = [] Angles = [] if pnt: for k in range(len(pnt)): Rays.append(ghc.Vector2Pt(ShadingOrigin,pnt[k], False).vector) Angles.append(ghc.Angle(surface_normal , Rays[k]).angle) KeyPoints.append(pnt[Angles.index(max(Angles))]) # Find the relevant highest / closest point Rays = [] Angles = [] for i in range(len(KeyPoints)): Rays.append(ghc.Vector2Pt(surface_normal, KeyPoints[i], False).vector) Angles.append(ghc.Angle(surface_normal, Rays[i]).angle) KeyPoint = KeyPoints[Angles.index(max(Angles))] # Use the point it finds to deliver the Height and Distance for the PHPP Shading Calculator h_hori = KeyPoint.Z - ShadingOrigin.Z #Vertical distance Hypot = ghc.Length(ghc.Line(ShadingOrigin, KeyPoint)) d_hori = math.sqrt(Hypot**2 - h_hori**2) CheckLine = ghc.Line(ShadingOrigin, KeyPoint) else: h_hori = None d_hori = None CheckLine = HorizontalLine return h_hori, d_hori, CheckLine