forked from s_ranjbar/city_retrofit
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
e79439e144
|
@ -30,7 +30,8 @@ class Polyhedron:
|
|||
self._min_z = None
|
||||
self._min_y = 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):
|
||||
vertices = self.vertices
|
||||
|
@ -53,7 +54,7 @@ class Polyhedron:
|
|||
found = False
|
||||
for vertex_2 in self._vertices:
|
||||
found = False
|
||||
if self._geometry.almost_equal(vertex_1, vertex_2):
|
||||
if self._geometry.almost_equal(vertex_1, vertex_2, True):
|
||||
found = True
|
||||
break
|
||||
if not found:
|
||||
|
@ -99,7 +100,7 @@ class Polyhedron:
|
|||
|
||||
def _triangulate(self, surface):
|
||||
triangles = []
|
||||
complementary_surface = None
|
||||
complementary_surface = surface
|
||||
triangles_count = len(surface.points) - 2
|
||||
points_list = surface.points_list
|
||||
point_index = 0
|
||||
|
@ -110,7 +111,21 @@ class Polyhedron:
|
|||
# todo: use enum to describe triangle or rest instead 0 1
|
||||
right_area = right_direction[0].area + right_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
|
||||
point_index = 0
|
||||
triangles.append(left_direction[0])
|
||||
|
@ -124,8 +139,10 @@ class Polyhedron:
|
|||
complementary_surface = right_direction[1]
|
||||
else:
|
||||
point_index = point_index + 3
|
||||
if point_index > len(points_list):
|
||||
raise Exception('not ear found!')
|
||||
if point_index >= len(points_list):
|
||||
# print('wroooong', complementary_surface.type)
|
||||
# print(complementary_surface.points)
|
||||
return triangles
|
||||
if len(points_list) == 9:
|
||||
# the rest point's are already a triangle
|
||||
triangles.append(complementary_surface)
|
||||
|
|
|
@ -6,6 +6,7 @@ contributors: Pilar Monsalvete pilar_monsalvete@yahoo.es
|
|||
"""
|
||||
from __future__ import annotations
|
||||
from typing import Union
|
||||
import sys
|
||||
|
||||
import numpy as np
|
||||
import pyny3d.geoms as pn
|
||||
|
@ -209,7 +210,7 @@ class Surface:
|
|||
# New method to calculate area
|
||||
if self._area is None:
|
||||
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
|
||||
alpha = 0
|
||||
vec_1 = self.points[1] - self.points[0]
|
||||
|
@ -217,7 +218,7 @@ class Surface:
|
|||
vec_2 = self.points[i] - self.points[0]
|
||||
alpha += self.angle_between_vectors(vec_1, vec_2)
|
||||
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
|
||||
horizontal_points = self.rotate_surface_to_horizontal(self)
|
||||
area = 0
|
||||
|
|
|
@ -46,7 +46,7 @@ class GeometryHelper:
|
|||
delta = math.fabs(a1 - a2)
|
||||
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)
|
||||
:param v1: [x,y,z]
|
||||
|
|
Loading…
Reference in New Issue
Block a user