Repository: santoshphilip/eppy

Issue:
surface.azimuth does not take into account the building.North_Axis
problem: surface.azimuth does not take into account the building.North_Axis

As a step to resolving this issue, we need a function

    def true_azimuth(building_north_axis, surface_azimuth)
        # return "the azimuth based on surface.azimuth and building.North_Axis"



The location of this function should be 

- eppy
    - geometry
        - surface.true_azimuth
        
The unit tests should be in

- eppy
    - tests
        - test_surface.py

This issue is assigned to @airallergy

@airallergy, see https://github.com/santoshphilip/eppy/blob/master/CONTRIBUTING.md and use the second method where you fork the repository and then do a pull request

Comments:

Patch:
diff --git a/eppy/bunch_subclass.py b/eppy/bunch_subclass.py
index 445576f..ba78e47 100644
--- a/eppy/bunch_subclass.py
+++ b/eppy/bunch_subclass.py
@@ -100,6 +100,7 @@ def addfunctions(abunch):
             "height": fh.height,  # not working correctly
             "width": fh.width,  # not working correctly
             "azimuth": fh.azimuth,
+            "true_azimuth": fh.true_azimuth,
             "tilt": fh.tilt,
             "coords": fh.getcoords,  # needed for debugging
         }
diff --git a/eppy/function_helpers.py b/eppy/function_helpers.py
index c455986..140e569 100644
--- a/eppy/function_helpers.py
+++ b/eppy/function_helpers.py
@@ -57,6 +57,15 @@ def azimuth(ddtt):
     return g_surface.azimuth(coords)
 
 
+def true_azimuth(ddtt):
+    """azimuth of the surface"""
+    idf = ddtt.theidf
+    building_north_axis = idf.idfobjects["building".upper()][0].North_Axis
+    coords = getcoords(ddtt)
+    surface_azimuth = g_surface.azimuth(coords)
+    return g_surface.true_azimuth(building_north_axis, surface_azimuth)
+
+
 def tilt(ddtt):
     """tilt of the surface"""
     coords = getcoords(ddtt)
diff --git a/eppy/geometry/surface.py b/eppy/geometry/surface.py
index 69211f6..8d2bfb9 100644
--- a/eppy/geometry/surface.py
+++ b/eppy/geometry/surface.py
@@ -131,6 +131,12 @@ def azimuth(poly):
         return angle2vecs(vec_azi, vec_n)
 
 
+def true_azimuth(building_north_axis, surface_azimuth):
+    """True azimuth of a polygon poly"""
+    building_north_axis = 0 if building_north_axis == "" else building_north_axis
+    return (building_north_axis + surface_azimuth) % 360
+
+
 def tilt(poly):
     """Tilt of a polygon poly"""
     num = len(poly) - 1


Test patch:
diff --git a/eppy/tests/geometry_tests/test_surface.py b/eppy/tests/geometry_tests/test_surface.py
index c57fec7..6d5b32c 100644
--- a/eppy/tests/geometry_tests/test_surface.py
+++ b/eppy/tests/geometry_tests/test_surface.py
@@ -106,6 +106,19 @@ def test_azimuth():
         assert almostequal(answer, result, places=3) == True
 
 
+def test_true_azimuth():
+    """test the true azimuth of a polygon poly"""
+    data = (
+        ("", 180, 180),
+        # building_north_axis, surface_azimuth, answer,
+        (20, 0, 20),
+        (240, 180, 60),
+    )
+    for building_north_axis, surface_azimuth, answer in data:
+        result = surface.true_azimuth(building_north_axis, surface_azimuth)
+        assert almostequal(answer, result, places=3) == True
+
+
 def test_tilt():
     """test the tilt of a polygon poly"""
     data = (