diff --git a/city_model_structure/attributes/surface.py b/city_model_structure/attributes/surface.py index ecd9efcb..f38a571a 100644 --- a/city_model_structure/attributes/surface.py +++ b/city_model_structure/attributes/surface.py @@ -49,6 +49,7 @@ class Surface: self._shared_surfaces = [] self._global_irradiance = dict() self._ground_coordinates = (self.min_x, self.min_y, self.min_z) + self._is_planar = None def parent(self, parent, surface_id): """ @@ -480,3 +481,17 @@ class Surface: @property def convex(self): return pn.Polygon.is_convex(self.polygon.points) + + @property + def is_planar(self) -> bool: + if self._is_planar is None: + self._is_planar = True + vectors = [] + for i in range(1,len(self.points)): + vectors.append(self.points[i] - self.points[0]) + for i in range(2, len(vectors)): + product = np.dot(np.cross(vectors[0], vectors[1]), vectors[i]) + if math.fabs(product) > 1e-4: + self._is_planar = False + break + return self._is_planar