Correct surface triangulation algorithms
This commit is contained in:
parent
15f6312992
commit
9c0483f1d8
|
@ -105,12 +105,9 @@ class Polyhedron:
|
|||
return (Surface(triangle_left, remove_last=False), Surface(rest_points_left, remove_last=False)), \
|
||||
(Surface(triangle_right, remove_last=False), Surface(rest_points_right, remove_last=False))
|
||||
|
||||
def _print(self, surface):
|
||||
for point in surface.points:
|
||||
print(point[0]-surface.min_x, point[1]-surface.min_y, point[2]-surface.min_z)
|
||||
|
||||
def _triangulate(self, surface):
|
||||
triangles = []
|
||||
complementary_surface = None
|
||||
triangles_count = len(surface.points) - 2
|
||||
points_list = surface.points_list
|
||||
point_index = 0
|
||||
|
@ -126,18 +123,21 @@ class Polyhedron:
|
|||
point_index = 0
|
||||
triangles.append(left_direction[0])
|
||||
points_list = left_direction[1].points_list
|
||||
complementary_surface = left_direction[1]
|
||||
elif self._geometry.almost_same_area(area, right_area):
|
||||
area = right_direction[1].area
|
||||
point_index = 0
|
||||
triangles.append(right_direction[0])
|
||||
points_list = right_direction[1].points_list
|
||||
complementary_surface = right_direction[1]
|
||||
else:
|
||||
point_index = point_index + 3
|
||||
if point_index > len(points_list):
|
||||
raise Exception('not ear found!')
|
||||
if len(points_list) == 9:
|
||||
# the rest point's are already a triangle
|
||||
triangles.append(Surface(points_list, remove_last=False))
|
||||
triangles.append(complementary_surface)
|
||||
|
||||
return triangles
|
||||
|
||||
@property
|
||||
|
@ -160,6 +160,7 @@ class Polyhedron:
|
|||
for sub_surface in sub_surfaces:
|
||||
face = []
|
||||
points = sub_surface.points
|
||||
print(points)
|
||||
for point in points:
|
||||
face.append(self._position_of(point, face))
|
||||
self._faces.append(face)
|
||||
|
@ -172,6 +173,7 @@ class Polyhedron:
|
|||
@property
|
||||
def _polyhedron_mesh(self):
|
||||
if self._mesh is None:
|
||||
print(self.faces)
|
||||
self._mesh = Trimesh(vertices=self.vertices, faces=self.faces)
|
||||
return self._mesh
|
||||
|
||||
|
@ -272,12 +274,15 @@ class Polyhedron:
|
|||
return self._min_x
|
||||
|
||||
@property
|
||||
def centroid(self):
|
||||
def center(self):
|
||||
"""
|
||||
Polyhedron centroid
|
||||
:return: [x,y,z]
|
||||
"""
|
||||
return [self.max_x - self.min_x, self.max_y - self.min_y, self.max_z - self.min_z]
|
||||
x = (self.max_x + self.min_x) / 2
|
||||
y = (self.max_y + self.min_y) / 2
|
||||
z = (self.max_z + self.min_z) / 2
|
||||
return [x, y, z]
|
||||
|
||||
def stl_export(self, full_path):
|
||||
"""
|
||||
|
|
|
@ -13,6 +13,8 @@ import math
|
|||
|
||||
from helpers.geometry_helper import GeometryHelper
|
||||
|
||||
# todo: remove pyny3d, seems to not be supported and has some issues
|
||||
|
||||
|
||||
class Surface:
|
||||
"""
|
||||
|
|
|
@ -66,7 +66,7 @@ class CityObject:
|
|||
"""
|
||||
if self._polyhedron is None:
|
||||
self._polyhedron = Polyhedron(self.surfaces)
|
||||
return self._polyhedron.centroid
|
||||
return self._polyhedron.center
|
||||
|
||||
def stl_export(self, path):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue
Block a user