Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(shades): fix fixed shades #27

Merged
merged 1 commit into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 0 additions & 34 deletions honeybee_doe2/geometry/polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,6 @@ def __init__(self, name, vertices, flip=False):
self.vertices = vertices
self.flip = flip

@classmethod
def from_shade(cls, shade: Shade, flip=False):
name = short_name(shade.display_name)

geometry: Face3D = shade.geometry

rel_plane = geometry.plane
# horizontal Face3D; use world XY
angle_tolerance = 0.01
if rel_plane.n.angle(Vector3D(0, 0, 1)) <= angle_tolerance or \
rel_plane.n.angle(Vector3D(0, 0, -1)) <= angle_tolerance:
llc_3d = geometry.lower_left_corner
llc = Point2D(llc_3d.x, llc_3d.y)
vertices = [
Point2D(v[0] - llc.x, v[1] - llc.y) for v in
geometry.lower_left_counter_clockwise_vertices
]

if not flip and \
rel_plane.n.angle(Vector3D(0, 0, -1)) <= angle_tolerance:
# change the order of the vertices. DOE2 expects the vertices to be
# CCW from the top view
vertices = [vertices[0]] + list(reversed(vertices[1:]))

else: # vertical or tilted Face3D; orient the Y to the world Z
proj_y = Vector3D(0, 0, 1).project(rel_plane.n)
proj_x = proj_y.rotate(rel_plane.n, math.pi / -2)
ref_plane = Plane(rel_plane.n, geometry.lower_left_corner, proj_x)
vertices = [
Point2D(*ref_plane.xyz_to_xy(pt))
for pt in geometry.lower_left_counter_clockwise_vertices]

return cls(name=name, vertices=vertices, flip=flip)

@classmethod
def from_face(cls, face: Face, flip=False):
"""
Expand Down
42 changes: 24 additions & 18 deletions honeybee_doe2/properties/shades.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,26 @@ class Doe2Shade:
def from_shade(cls, shade: Shade):
"""Generate doe2 fixed shades shades"""
name = short_name(shade.display_name)
flip = False if shade.geometry.normal.z <= 0 else True
shade_type = 'FIXED-SHADE'
ref_geo = shade.geometry
if flip == True:
ref_geo = ref_geo.flip()
ref = ref_geo.lower_left_corner

tilt = 90 - ref_geo.altitude
azimuth = ref_geo.azimuth

x_ref = ref.x
y_ref = ref.y
z_ref = ref.z
polygon = DoePolygon.from_shade(shade, flip=flip)
tolerance = 0.001
if abs(shade.altitude + 90) <= tolerance:
# horizontal facing down - flip the face so we can deal with them like
# upwards facing shades. It doesn't make a difference in the results
geometry = shade.geometry.flip()
shade = Shade(name, geometry=geometry, is_detached=shade.is_detached)

llc = shade.geometry.lower_left_corner
tilt = 90 - shade.altitude
azimuth = shade.azimuth
if abs(tilt) <= tolerance:
# set the azimuth to 180 for all the horizontal shade faces
azimuth = 180

x_ref = llc.x
y_ref = llc.y
z_ref = llc.z

polygon = DoePolygon.from_face(shade)

return cls(
name=name, shade_type=shade_type, x_ref=x_ref, y_ref=y_ref, z_ref=z_ref,
Expand All @@ -62,13 +68,13 @@ def to_inp(self):
"""Returns *.inp shade object string"""
obj_lines = [self.polygon.to_inp(), '\n\n']

obj_lines.append(f'"{self.name}" = {self.shade_type}\n')
obj_lines.append(f' SHAPE = POLYGON\n')
obj_lines.append(f'"{self.name}" = {self.shade_type}\n')
obj_lines.append(' SHAPE = POLYGON\n')
obj_lines.append(f' POLYGON = "{self.name} Plg"\n')
obj_lines.append(f' TRANSMITTANCE = {self.transmittance}\n')
obj_lines.append(f' X = {self.x_ref}\n')
obj_lines.append(f' Y = {self.y_ref}\n')
obj_lines.append(f' Z = {self.z_ref}\n')
obj_lines.append(f' X-REF = {self.x_ref}\n')
obj_lines.append(f' Y-REF = {self.y_ref}\n')
obj_lines.append(f' Z-REF = {self.z_ref}\n')
obj_lines.append(f' TILT = {self.tilt}\n')
obj_lines.append(f' AZIMUTH = {self.azimuth}\n ..\n')

Expand Down
Loading