added is_planar

This commit is contained in:
Pilar 2021-01-13 12:22:10 -05:00
parent e9dd9c2221
commit a53d48e49d

View File

@ -49,6 +49,7 @@ class Surface:
self._shared_surfaces = [] self._shared_surfaces = []
self._global_irradiance = dict() self._global_irradiance = dict()
self._ground_coordinates = (self.min_x, self.min_y, self.min_z) self._ground_coordinates = (self.min_x, self.min_y, self.min_z)
self._is_planar = None
def parent(self, parent, surface_id): def parent(self, parent, surface_id):
""" """
@ -480,3 +481,17 @@ class Surface:
@property @property
def convex(self): def convex(self):
return pn.Polygon.is_convex(self.polygon.points) 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