Merge remote-tracking branch 'origin/master'

This commit is contained in:
pilar 2021-01-05 15:01:46 -05:00
commit e79439e144
3 changed files with 27 additions and 9 deletions

View File

@ -30,7 +30,8 @@ class Polyhedron:
self._min_z = None self._min_z = None
self._min_y = None self._min_y = None
self._min_x = None self._min_x = None
self._geometry = GeometryHelper(delta=0.0, area_delta=0.5) self._geometry = GeometryHelper(delta=5.0, area_delta=0.01)
print(f'[{self._geometry._area_delta} {self._geometry._delta}]')
def _position_of(self, point, face): def _position_of(self, point, face):
vertices = self.vertices vertices = self.vertices
@ -53,7 +54,7 @@ class Polyhedron:
found = False found = False
for vertex_2 in self._vertices: for vertex_2 in self._vertices:
found = False found = False
if self._geometry.almost_equal(vertex_1, vertex_2): if self._geometry.almost_equal(vertex_1, vertex_2, True):
found = True found = True
break break
if not found: if not found:
@ -99,7 +100,7 @@ class Polyhedron:
def _triangulate(self, surface): def _triangulate(self, surface):
triangles = [] triangles = []
complementary_surface = None complementary_surface = surface
triangles_count = len(surface.points) - 2 triangles_count = len(surface.points) - 2
points_list = surface.points_list points_list = surface.points_list
point_index = 0 point_index = 0
@ -110,7 +111,21 @@ class Polyhedron:
# todo: use enum to describe triangle or rest instead 0 1 # todo: use enum to describe triangle or rest instead 0 1
right_area = right_direction[0].area + right_direction[1].area right_area = right_direction[0].area + right_direction[1].area
left_area = left_direction[0].area + left_direction[1].area left_area = left_direction[0].area + left_direction[1].area
if self._geometry.almost_same_area(area, left_area): if self._geometry.almost_same_area(area, left_area) and self._geometry.almost_same_area(area, right_area):
# Both seems to be an ear, choose the more precise
if np.abs(left_area-area) < np.abs(right_area-area):
area = left_direction[1].area
point_index = 0
triangles.append(left_direction[0])
points_list = left_direction[1].points_list
complementary_surface = left_direction[1]
else:
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]
elif self._geometry.almost_same_area(area, left_area):
area = left_direction[1].area area = left_direction[1].area
point_index = 0 point_index = 0
triangles.append(left_direction[0]) triangles.append(left_direction[0])
@ -124,8 +139,10 @@ class Polyhedron:
complementary_surface = right_direction[1] complementary_surface = right_direction[1]
else: else:
point_index = point_index + 3 point_index = point_index + 3
if point_index > len(points_list): if point_index >= len(points_list):
raise Exception('not ear found!') # print('wroooong', complementary_surface.type)
# print(complementary_surface.points)
return triangles
if len(points_list) == 9: if len(points_list) == 9:
# the rest point's are already a triangle # the rest point's are already a triangle
triangles.append(complementary_surface) triangles.append(complementary_surface)

View File

@ -6,6 +6,7 @@ contributors: Pilar Monsalvete pilar_monsalvete@yahoo.es
""" """
from __future__ import annotations from __future__ import annotations
from typing import Union from typing import Union
import sys
import numpy as np import numpy as np
import pyny3d.geoms as pn import pyny3d.geoms as pn
@ -209,7 +210,7 @@ class Surface:
# New method to calculate area # New method to calculate area
if self._area is None: if self._area is None:
if len(self.points) < 3: if len(self.points) < 3:
print('Warning: the area of a line or point cannot be calculated. Area = 0') sys.stderr.write('Warning: the area of a line or point cannot be calculated. Area = 0\n')
return 0 return 0
alpha = 0 alpha = 0
vec_1 = self.points[1] - self.points[0] vec_1 = self.points[1] - self.points[0]
@ -217,7 +218,7 @@ class Surface:
vec_2 = self.points[i] - self.points[0] vec_2 = self.points[i] - self.points[0]
alpha += self.angle_between_vectors(vec_1, vec_2) alpha += self.angle_between_vectors(vec_1, vec_2)
if alpha == 0: if alpha == 0:
print('Warning: the area of a line or point cannot be calculated. Area = 0') sys.stderr.write('Warning: the area of a line or point cannot be calculated. Area = 0\n')
return 0 return 0
horizontal_points = self.rotate_surface_to_horizontal(self) horizontal_points = self.rotate_surface_to_horizontal(self)
area = 0 area = 0

View File

@ -46,7 +46,7 @@ class GeometryHelper:
delta = math.fabs(a1 - a2) delta = math.fabs(a1 - a2)
return delta <= self._area_delta return delta <= self._area_delta
def almost_equal(self, v1, v2): def almost_equal(self, v1, v2, debug=False):
""" """
Compare two points and decides if they are almost equal (quadratic error under delta) Compare two points and decides if they are almost equal (quadratic error under delta)
:param v1: [x,y,z] :param v1: [x,y,z]