From 088d7a341161e8901430aa3d4cebc773c7a304e1 Mon Sep 17 00:00:00 2001 From: Chris Mackey Date: Sat, 25 May 2024 10:48:15 -0700 Subject: [PATCH] fix(writer): Fix issue with skylight origin --- honeybee_idaice/face.py | 7 +++++-- honeybee_idaice/writer.py | 21 ++++++++++++--------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/honeybee_idaice/face.py b/honeybee_idaice/face.py index 5918000..014b8bd 100644 --- a/honeybee_idaice/face.py +++ b/honeybee_idaice/face.py @@ -8,7 +8,7 @@ def opening_to_idm( opening: Union[Aperture, Door], ref_plane: Plane, - is_aperture=True, decimal_places: int = 3) -> str: + is_aperture=True, decimal_places: int = 3, angle_tolerance: float = 1.0) -> str: """Translate a HBJSON aperture or Door to an IDM Window. Args: @@ -20,12 +20,15 @@ def opening_to_idm( Door. (Default: True). decimal_places: An integer for the number of decimal places to which coordinate values will be rounded. (Default: 3). + angle_tolerance: The max angle in degrees that opening normal can differ + from the World Z before the opening is treated as being in the + World XY plane. (Default: 1). """ # get the name name = opening.identifier # if the aperture is horizontal, use the world XY - ang_tol = math.radians(1) + ang_tol = math.radians(angle_tolerance) vertical = Vector3D(0, 0, 1) vert_ang = ref_plane.n.angle(vertical) if vert_ang <= ang_tol or vert_ang >= math.pi - ang_tol: diff --git a/honeybee_idaice/writer.py b/honeybee_idaice/writer.py index 933fed9..d39f7bf 100644 --- a/honeybee_idaice/writer.py +++ b/honeybee_idaice/writer.py @@ -5,7 +5,7 @@ from typing import List, Tuple from ladybug_geometry.bounding import bounding_box -from ladybug_geometry.geometry3d import Point3D, Face3D +from ladybug_geometry.geometry3d import Vector3D, Point3D, Plane, Face3D from honeybee.model import Model, Room from honeybee.facetype import RoofCeiling, Wall, Floor, AirBoundary, get_type_from_normal @@ -93,13 +93,17 @@ def ceilings_to_idm( for vv in contours for v in vv ) - # add apertures - ref_plane = face_reference_plane(face, angle_tolerance) \ - if face.has_sub_faces else None + # add apertures and doors windows = [''] - for aperture in face.apertures: - windows.append(opening_to_idm(aperture, ref_plane, decimal_places=dpl)) - + if face.has_sub_faces: + if angle_tolerance < face.tilt < 180 - angle_tolerance: + ref_plane = face_reference_plane(face, angle_tolerance) + else: + ref_plane = Plane(n=Vector3D(0, 0, 1), o=origin, x=Vector3D(1, 0, 0)) + for aperture in face.apertures: + op_str = opening_to_idm(aperture, ref_plane, decimal_places=dpl, + angle_tolerance=angle_tolerance) + windows.append(op_str) windows = ''.join(windows) cp = f' ((ENCLOSING-ELEMENT :N "{name}" :T CEILING-PART :INDEX {-1001 - fc})\n' \ @@ -154,8 +158,7 @@ def room_to_idm( horiz_boundary = hz_bounds[0] if horiz_boundary.normal.z <= 0: # ensure upward-facing Face3D horiz_boundary = horiz_boundary.flip() - ordered_vertices = horiz_boundary.lower_left_counter_clockwise_vertices - origin = ordered_vertices[0] + origin = horiz_boundary.min if horiz_boundary.is_convex: pole = horiz_boundary.center else: # use a 1 cm tolerance for pole that will not be time consuming to compute