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:
parent
0792d87394
commit
41a64ab470
31
field.py
31
field.py
|
|
@ -934,23 +934,20 @@ class Features3d:
|
|||
# @staticmethod
|
||||
# def ray_triangle_intersect(self):
|
||||
|
||||
def ray_triangle_intersect(r0,dr,v0,v1,v2):
|
||||
v0v1 = v1-v0
|
||||
v0v2 = v2-v0
|
||||
pvec = np.cross(dr,v0v2)
|
||||
det = np.dot(v0v1,pvec)
|
||||
if np.abs(det)<1e-6:
|
||||
return float('-inf')
|
||||
invDet = 1.0 / det
|
||||
tvec = r0-v0
|
||||
u = np.dot(tvec,pvec)*invDet
|
||||
if u<0 or u>1:
|
||||
return float('-inf')
|
||||
qvec = np.cross(tvec,v0v1)
|
||||
v = np.dot(dr,qvec)*invDet
|
||||
if v<0 or u+v>1:
|
||||
return float('-inf')
|
||||
return np.dot(v0v2,qvec)*invDet
|
||||
def ray_triangle_intersect(R,dR,A,B,C):
|
||||
E1 = B-A
|
||||
E2 = C-A
|
||||
N = np.cross(E1,E2)
|
||||
det = -np.dot(dR,N)
|
||||
invdet = 1.0/det
|
||||
AO = R-A
|
||||
DAO = np.cross(AO,dR)
|
||||
# u,v,1-u-v are the barycentric coordinates of intersection
|
||||
u = np.dot(E2,DAO)*invdet
|
||||
v = -np.dot(E1,DAO)*invdet
|
||||
# Intersection point is R+t*dR
|
||||
t = np.dot(AO,N)*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
|
||||
|
||||
def clean_points(self,report=False):
|
||||
nfaces_ = self._faces.shape[0]
|
||||
|
|
|
|||
Loading…
Reference in New Issue