Commit 3b91d5d1 authored by sumpfralle's avatar sumpfralle

prevent each collision detection code to be triggered by a "touch" (this...

prevent each collision detection code to be triggered by a "touch" (this avoids problems with float inaccuracies)


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@699 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 8b0e1df7
...@@ -136,7 +136,7 @@ class BaseCutter(object): ...@@ -136,7 +136,7 @@ class BaseCutter(object):
if cp: if cp:
# check if the contact point is between the endpoints # check if the contact point is between the endpoints
m = cp.sub(edge.p1).dot(edge.dir) m = cp.sub(edge.p1).dot(edge.dir)
if (m < 0) or (m > edge.len + epsilon): if (m < -epsilon) or (m > edge.len + epsilon):
return (None, INFINITE, cp) return (None, INFINITE, cp)
return (cl, l, cp) return (cl, l, cp)
...@@ -151,7 +151,7 @@ class BaseCutter(object): ...@@ -151,7 +151,7 @@ class BaseCutter(object):
def intersect_cylinder_vertex(self, direction, point): def intersect_cylinder_vertex(self, direction, point):
(cl, ccp, cp, l) = self.intersect_cylinder_point(direction, point) (cl, ccp, cp, l) = self.intersect_cylinder_point(direction, point)
if ccp and ccp.z < self.center.z - epsilon: if ccp and ccp.z < self.center.z + epsilon:
return (None, INFINITE, None) return (None, INFINITE, None)
return (cl, l, cp) return (cl, l, cp)
...@@ -169,9 +169,9 @@ class BaseCutter(object): ...@@ -169,9 +169,9 @@ class BaseCutter(object):
if not ccp: if not ccp:
return (None, INFINITE, None) return (None, INFINITE, None)
m = cp.sub(edge.p1).dot(edge.dir) m = cp.sub(edge.p1).dot(edge.dir)
if (m < 0) or (m > edge.len + epsilon): if (m < -epsilon) or (m > edge.len + epsilon):
return (None, INFINITE, None) return (None, INFINITE, None)
if ccp.z < self.center.z - epsilon: if ccp.z < self.center.z + epsilon:
return (None, INFINITE, None) return (None, INFINITE, None)
return (cl, l, cp) return (cl, l, cp)
...@@ -184,7 +184,7 @@ class SphericalCutter(BaseCutter): ...@@ -184,7 +184,7 @@ class SphericalCutter(BaseCutter):
# check if the contact point is between the endpoints # check if the contact point is between the endpoints
d = edge.p2.sub(edge.p1) d = edge.p2.sub(edge.p1)
m = cp.sub(edge.p1).dot(d) m = cp.sub(edge.p1).dot(d)
if (m < 0) or (m > d.normsq + epsilon): if (m < -epsilon) or (m > d.normsq + epsilon):
return (None, INFINITE, None) return (None, INFINITE, None)
return (cl, l, cp) return (cl, l, cp)
......
...@@ -205,7 +205,7 @@ class ToroidalCutter(BaseCutter): ...@@ -205,7 +205,7 @@ class ToroidalCutter(BaseCutter):
return (None, INFINITE, None) return (None, INFINITE, None)
if ccp: if ccp:
m = cp.sub(edge.p1).dot(edge.dir) m = cp.sub(edge.p1).dot(edge.dir)
if (m < 0) or (m > edge.len + epsilon): if (m < -epsilon) or (m > edge.len + epsilon):
return (None, INFINITE, None) return (None, INFINITE, None)
return (cl, l, cp) return (cl, l, cp)
......
...@@ -63,7 +63,7 @@ def intersect_cylinder_point(center, axis, radius, radiussq, direction, point): ...@@ -63,7 +63,7 @@ def intersect_cylinder_point(center, axis, radius, radiussq, direction, point):
n = direction.cross(axis).normalized() n = direction.cross(axis).normalized()
# distance of the point to this plane # distance of the point to this plane
d = n.dot(point) - n.dot(center) d = n.dot(point) - n.dot(center)
if abs(d) > radius + epsilon: if abs(d) > radius - epsilon:
return (None, None, INFINITE) return (None, None, INFINITE)
# ccl is on cylinder # ccl is on cylinder
d2 = sqrt(radiussq-d*d) d2 = sqrt(radiussq-d*d)
...@@ -135,7 +135,7 @@ def intersect_circle_point(center, axis, radius, radiussq, direction, point): ...@@ -135,7 +135,7 @@ def intersect_circle_point(center, axis, radius, radiussq, direction, point):
# intersect with line gives ccp # intersect with line gives ccp
(ccp, l) = plane.intersect_point(direction, point) (ccp, l) = plane.intersect_point(direction, point)
# check if inside circle # check if inside circle
if ccp and (center.sub(ccp).normsq <= radiussq): if ccp and (center.sub(ccp).normsq < radiussq - epsilon):
return (ccp, point, -l) return (ccp, point, -l)
return (None, None, INFINITE) return (None, None, INFINITE)
...@@ -150,17 +150,17 @@ def intersect_circle_line(center, axis, radius, radiussq, direction, edge): ...@@ -150,17 +150,17 @@ def intersect_circle_line(center, axis, radius, radiussq, direction, edge):
(p2, l) = plane.intersect_point(direction, edge.p2) (p2, l) = plane.intersect_point(direction, edge.p2)
pc = Line(p1, p2).closest_point(center) pc = Line(p1, p2).closest_point(center)
d_sq = pc.sub(center).normsq d_sq = pc.sub(center).normsq
if d_sq > radiussq: if d_sq > radiussq - epsilon:
return (None, None, INFINITE) return (None, None, INFINITE)
a = sqrt(radiussq - d_sq) a = sqrt(radiussq - d_sq)
d1 = p1.sub(pc).dot(d) d1 = p1.sub(pc).dot(d)
d2 = p2.sub(pc).dot(d) d2 = p2.sub(pc).dot(d)
ccp = None ccp = None
cp = None cp = None
if abs(d1) < a + epsilon: if abs(d1) < a - epsilon:
ccp = p1 ccp = p1
cp = p1.sub(direction.mul(l)) cp = p1.sub(direction.mul(l))
elif abs(d2) < a + epsilon: elif abs(d2) < a - epsilon:
ccp = p2 ccp = p2
cp = p2.sub(direction.mul(l)) cp = p2.sub(direction.mul(l))
elif ((d1 < -a + epsilon) and (d2 > a - epsilon)) \ elif ((d1 < -a + epsilon) and (d2 > a - epsilon)) \
...@@ -193,7 +193,7 @@ def intersect_circle_line(center, axis, radius, radiussq, direction, edge): ...@@ -193,7 +193,7 @@ def intersect_circle_line(center, axis, radius, radiussq, direction, edge):
# distance from center to this plane # distance from center to this plane
dist = n2.dot(center) - n2.dot(lp) dist = n2.dot(center) - n2.dot(lp)
distsq = dist * dist distsq = dist * dist
if distsq > radiussq: if distsq > radiussq - epsilon:
return (None, None, INFINITE) return (None, None, INFINITE)
# must be on circle # must be on circle
dist2 = sqrt(radiussq - distsq) dist2 = sqrt(radiussq - distsq)
...@@ -251,7 +251,7 @@ def intersect_sphere_line(center, radius, radiussq, direction, edge): ...@@ -251,7 +251,7 @@ def intersect_sphere_line(center, radius, radiussq, direction, edge):
# calculate the distance from the sphere center to the plane # calculate the distance from the sphere center to the plane
dist = - center.dot(n) - edge.p1.dot(n) dist = - center.dot(n) - edge.p1.dot(n)
if abs(dist) > radius: if abs(dist) > radius - epsilon:
return (None, None, INFINITE) return (None, None, INFINITE)
# this gives us the intersection circle on the sphere # this gives us the intersection circle on the sphere
...@@ -301,7 +301,7 @@ def intersect_torus_point(center, axis, majorradius, minorradius, majorradiussq, ...@@ -301,7 +301,7 @@ def intersect_torus_point(center, axis, majorradius, minorradius, majorradiussq,
minlsq = (majorradius - minorradius) ** 2 minlsq = (majorradius - minorradius) ** 2
maxlsq = (majorradius + minorradius) ** 2 maxlsq = (majorradius + minorradius) ** 2
l_sq = (point.x-center.x) ** 2 + (point.y - center.y) ** 2 l_sq = (point.x-center.x) ** 2 + (point.y - center.y) ** 2
if (l_sq < minlsq - epsilon) or (l_sq > maxlsq + epsilon): if (l_sq < minlsq + epsilon) or (l_sq > maxlsq - epsilon):
return (None, None, INFINITE) return (None, None, INFINITE)
l = sqrt(l_sq) l = sqrt(l_sq)
z_sq = minorradiussq - (majorradius - l) ** 2 z_sq = minorradiussq - (majorradius - l) ** 2
...@@ -313,12 +313,12 @@ def intersect_torus_point(center, axis, majorradius, minorradius, majorradiussq, ...@@ -313,12 +313,12 @@ def intersect_torus_point(center, axis, majorradius, minorradius, majorradiussq,
elif direction.z == 0: elif direction.z == 0:
# push # push
z = point.z - center.z z = point.z - center.z
if abs(z) > minorradius + epsilon: if abs(z) > minorradius - epsilon:
return (None, None, INFINITE) return (None, None, INFINITE)
l = majorradius + sqrt(minorradiussq - z * z) l = majorradius + sqrt(minorradiussq - z * z)
n = axis.cross(direction) n = axis.cross(direction)
d = n.dot(point) - n.dot(center) d = n.dot(point) - n.dot(center)
if abs(d) > l + epsilon: if abs(d) > l - epsilon:
return (None, None, INFINITE) return (None, None, INFINITE)
a = sqrt(l * l - d * d) a = sqrt(l * l - d * d)
ccp = center.add(n.mul(d).add(direction.mul(a))) ccp = center.add(n.mul(d).add(direction.mul(a)))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment