2020-05-19 17:00:15 -04:00
|
|
|
import math
|
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
|
|
|
|
class Geometry:
|
|
|
|
def __init__(self, delta=0.5):
|
|
|
|
self._delta = delta
|
|
|
|
|
|
|
|
def almost_equal(self, v1, v2):
|
2020-05-28 15:22:46 -04:00
|
|
|
delta = math.sqrt(pow((v1[0] - v2[0]), 2) + pow((v1[1] - v2[1]), 2) + pow((v1[2] - v2[2]), 2))
|
2020-05-19 17:00:15 -04:00
|
|
|
return delta <= self._delta
|
|
|
|
|
2020-05-28 15:22:46 -04:00
|
|
|
def is_almost_same_surface(self, s1, s2):
|
|
|
|
# delta is grads an need to be converted into radians
|
|
|
|
delta = np.rad2deg(self._delta)
|
|
|
|
difference = (s1.inclination - s2.inclination) % math.pi
|
|
|
|
if abs(difference) > delta:
|
|
|
|
return False
|
|
|
|
# s1 and s2 are at least almost parallel surfaces
|
2020-05-29 07:25:33 -04:00
|
|
|
# calculate distance point to plane using all the vertex
|
2020-05-28 15:22:46 -04:00
|
|
|
# select surface1 value for the point (X,Y,Z) where two of the values are 0
|
2020-06-03 16:56:17 -04:00
|
|
|
minimum_distance = self._delta + 1
|
2020-05-29 07:25:33 -04:00
|
|
|
parametric = s2.polygon.get_parametric()
|
2020-05-28 15:22:46 -04:00
|
|
|
n2 = s2.normal
|
2020-05-29 07:25:33 -04:00
|
|
|
for point in s1.points:
|
|
|
|
distance = abs(
|
|
|
|
(point[0] * parametric[0]) + (point[1] * parametric[1]) + (point[2] * parametric[2]) + parametric[3])
|
|
|
|
normal_module = math.sqrt(pow(n2[0], 2) + pow(n2[1], 2) + pow(n2[2], 2))
|
2020-06-03 16:56:17 -04:00
|
|
|
|
2020-05-29 07:25:33 -04:00
|
|
|
if normal_module == 0:
|
|
|
|
continue
|
|
|
|
distance = distance / normal_module
|
|
|
|
if distance < minimum_distance:
|
|
|
|
minimum_distance = distance
|
2020-06-03 16:56:17 -04:00
|
|
|
if minimum_distance <= self._delta:
|
|
|
|
break
|
|
|
|
if minimum_distance > self._delta or s1.intersect(s2) is None:
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
return True
|
2020-05-28 15:22:46 -04:00
|
|
|
|
2020-05-19 17:00:15 -04:00
|
|
|
@staticmethod
|
|
|
|
def to_points_matrix(points, remove_last=False):
|
2020-05-28 15:22:46 -04:00
|
|
|
rows = points.size // 3
|
2020-05-19 17:00:15 -04:00
|
|
|
points = points.reshape(rows, 3)
|
|
|
|
if remove_last:
|
2020-05-28 15:22:46 -04:00
|
|
|
points = np.delete(points, rows - 1, 0)
|
2020-05-19 17:00:15 -04:00
|
|
|
return points
|