switched to another formulation of the algorithm which computes surface normal of triangle: this is necessary for inside/outside check

This commit is contained in:
Michael Krayer 2021-08-12 10:34:56 +02:00
parent 0792d87394
commit 41a64ab470
1 changed files with 14 additions and 17 deletions

View File

@ -934,23 +934,20 @@ class Features3d:
# @staticmethod # @staticmethod
# def ray_triangle_intersect(self): # def ray_triangle_intersect(self):
def ray_triangle_intersect(r0,dr,v0,v1,v2): def ray_triangle_intersect(R,dR,A,B,C):
v0v1 = v1-v0 E1 = B-A
v0v2 = v2-v0 E2 = C-A
pvec = np.cross(dr,v0v2) N = np.cross(E1,E2)
det = np.dot(v0v1,pvec) det = -np.dot(dR,N)
if np.abs(det)<1e-6: invdet = 1.0/det
return float('-inf') AO = R-A
invDet = 1.0 / det DAO = np.cross(AO,dR)
tvec = r0-v0 # u,v,1-u-v are the barycentric coordinates of intersection
u = np.dot(tvec,pvec)*invDet u = np.dot(E2,DAO)*invdet
if u<0 or u>1: v = -np.dot(E1,DAO)*invdet
return float('-inf') # Intersection point is R+t*dR
qvec = np.cross(tvec,v0v1) t = np.dot(AO,N)*invdet
v = np.dot(dr,qvec)*invDet return (t,t*np.dot(N,dR)) if (np.abs(det) >= 1e-6 and u >= 0.0 and v >= 0.0 and (u+v) <= 1.0) else None
if v<0 or u+v>1:
return float('-inf')
return np.dot(v0v2,qvec)*invDet
def clean_points(self,report=False): def clean_points(self,report=False):
nfaces_ = self._faces.shape[0] nfaces_ = self._faces.shape[0]