From 215d62b62bc015030b1e01901896fa76e19782dd Mon Sep 17 00:00:00 2001 From: Pilar Date: Mon, 11 Jan 2021 10:25:34 -0500 Subject: [PATCH] created distance_between_points in geometry_helper.py, erased almost_equal in polyhedron points --- city_model_structure/attributes/polyhedron.py | 6 +++--- city_model_structure/attributes/usage_zone.py | 2 +- city_model_structure/city_object.py | 1 + config/configuration.ini | 2 +- helpers/geometry_helper.py | 14 ++++++++++++-- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/city_model_structure/attributes/polyhedron.py b/city_model_structure/attributes/polyhedron.py index d93fe41a..1c501f39 100644 --- a/city_model_structure/attributes/polyhedron.py +++ b/city_model_structure/attributes/polyhedron.py @@ -30,13 +30,13 @@ class Polyhedron: self._min_z = None self._min_y = None self._min_x = None - self._geometry = GeometryHelper(delta=5.0, area_delta=0.01) + self._geometry = GeometryHelper() def _position_of(self, point, face): vertices = self.vertices for i in range(len(vertices)): # ensure not duplicated vertex - if i not in face and self._geometry.almost_equal(vertices[i], point): + if i not in face and GeometryHelper.distance_between_points(vertices[i], point) == 0: return i return -1 @@ -53,7 +53,7 @@ class Polyhedron: found = False for vertex_2 in self._vertices: found = False - if self._geometry.almost_equal(vertex_1, vertex_2): + if GeometryHelper.distance_between_points(vertex_1, vertex_2) == 0: found = True break if not found: diff --git a/city_model_structure/attributes/usage_zone.py b/city_model_structure/attributes/usage_zone.py index a70daf69..efdd3c0c 100644 --- a/city_model_structure/attributes/usage_zone.py +++ b/city_model_structure/attributes/usage_zone.py @@ -27,7 +27,7 @@ class UsageZone: self._dhw_preparation_temperature = None self._electrical_app_average_consumption_sqm_year = None # todo: mechanical_air_change must come from library, talk to Rabeeh - # todo: check to code clean and un used attributes + # todo: check to clean code and un-used attributes self._mechanical_air_change = ConfigurationHelper().min_air_change self._occupancy = None self._schedules = None diff --git a/city_model_structure/city_object.py b/city_model_structure/city_object.py index 21cb91a6..3244fae9 100644 --- a/city_model_structure/city_object.py +++ b/city_model_structure/city_object.py @@ -19,6 +19,7 @@ class CityObject: self._lod = lod self._surfaces = surfaces self._polyhedron = None + self._geometry = GeometryHelper() @property def lod(self): diff --git a/config/configuration.ini b/config/configuration.ini index d63fb74c..e6854a35 100644 --- a/config/configuration.ini +++ b/config/configuration.ini @@ -20,4 +20,4 @@ min_air_change = 0.5 [buildings] max_location_distance_for_shared_walls = 100.0 -min_coordinate = -1.7976931348623157e+308 \ No newline at end of file +min_coordinate = -1.7976931348623157e+308 diff --git a/helpers/geometry_helper.py b/helpers/geometry_helper.py index a5d4e197..2014f1cb 100644 --- a/helpers/geometry_helper.py +++ b/helpers/geometry_helper.py @@ -37,7 +37,7 @@ class GeometryHelper: max_distance = ConfigurationHelper().max_location_distance_for_shared_walls x = location1[0] - location2[0] y = location1[1] - location2[1] - return math.sqrt(math.pow(x, 2) + math.pow(y, 2)) < max_distance + return GeometryHelper.distance_between_points(x, y) < max_distance def almost_same_area(self, a1, a2): """ @@ -58,7 +58,9 @@ class GeometryHelper: :param v2: [x,y,z] :return: Boolean """ - delta = math.sqrt(pow((v1[0] - v2[0]), 2) + pow((v1[1] - v2[1]), 2) + pow((v1[2] - v2[2]), 2)) + print('3 dimensions') + delta = self.distance_between_points(v1, v2) + print('delta', delta) return delta <= self._delta def is_almost_same_surface(self, s1, s2): @@ -246,3 +248,11 @@ class GeometryHelper: mesh.compute_vertex_normals() o3d.visualization.draw_geometries([mesh], mesh_show_back_face=True) return Trimesh(vertices=np.asarray(mesh.vertices), faces=np.asarray(mesh.triangles)) + + @staticmethod + def distance_between_points(vertex1, vertex2): + power = 0 + for dimension in range(0, len(vertex1)): + power += math.pow(vertex2[dimension]-vertex1[dimension], 2) + distance = math.sqrt(power) + return distance