Commit 09281b60 authored by lode_leroy's avatar lode_leroy

fix verticals intersection

git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@20 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent d0d05a83
...@@ -6,6 +6,37 @@ from pycam.Geometry.Plane import Plane ...@@ -6,6 +6,37 @@ from pycam.Geometry.Plane import Plane
from pycam.Geometry.Line import Line from pycam.Geometry.Line import Line
from pycam.Geometry.Point import Point from pycam.Geometry.Point import Point
def isNear(a, b):
return abs(a-b)<1e-6
def isZero(a):
return isNear(a,0)
def intersect_lines(xl,zl,nxl,nzl,xm,zm,nxm,nzm):
X = None
Z = None
# print "xl=",xl,", zl=",zl,"nxl=",nxl,", nzl=",nzl,", X=", X, ", Z=",Z,", xm=",xm,",zm=",zm, ", nxm=",nxm,",nzm=",nzm
if isZero(nzl) and isZero(nzm):
pass
elif isZero(nzl) or isZero(nxl):
X = xl
Z = zm + (xm-xl)*nxm/nzm
return (X,Z)
elif isZero(nzm) or isZero(nxm):
X = xm
Z = zl - (xm-xl)*nxl/nzl
return (X,Z)
else:
try:
X = (zl-zm+(xm*nxm/nzm-xl*nxl/nzl))/(nxm/nzm-nxl/nzl)
except:
pass
if X and xl < X and X < xm:
Z = zl + (X-xl)*nxl/nzl
return (X,Z)
return (None,None)
def intersect_plane_point(plane, direction, point): def intersect_plane_point(plane, direction, point):
denom = plane.n.dot(direction) denom = plane.n.dot(direction)
if denom == 0: if denom == 0:
......
from pycam.PathProcessors import * from pycam.PathProcessors import *
from pycam.Geometry import * from pycam.Geometry import *
from pycam.Geometry.utils import * from pycam.Geometry.utils import *
from pycam.Geometry.intersection import intersect_lines
class DropCutter: class DropCutter:
...@@ -52,14 +53,13 @@ class DropCutter: ...@@ -52,14 +53,13 @@ class DropCutter:
zl = cl_last.z zl = cl_last.z
xm = cl_max.x xm = cl_max.x
zm = cl_max.z zm = cl_max.z
try: (X,Z) = intersect_lines(xl, zl, nxl, nzl, xm, zm, nxm, nzm)
X = (zl-zm+(xm*nxm/nzm+xl*nxl/nzl))/(nxm/nzm+nxl/nzl) if X and xl < X and X < xm and (Z > zl or Z > zm):
Y = cl_last.y Y = cl_last.y
Z = zl + (X-xl)*nxl/nzm if Z<z0 or Z>z1:
if xl < X and X < xm: print "^", "xl=",xl,", zl=",zl,"nxl=",nxl,", nzl=",nzl,", X=", X, ", Z=",Z,", xm=",xm,",zm=",zm, ", nxm=",nxm,",nzm=",nzm
else:
pa.append(Point(X,Y,Z)) pa.append(Point(X,Y,Z))
except:
pass
pa.append(cl_max) pa.append(cl_max)
cl_last = cl_max cl_last = cl_max
...@@ -100,22 +100,21 @@ class DropCutter: ...@@ -100,22 +100,21 @@ class DropCutter:
else: else:
pa.append(Point(cl_max.x,cl_max.y,cl_last.z)) pa.append(Point(cl_max.x,cl_max.y,cl_last.z))
elif (t_max and t_last and cl_last and cl_max ) and (t_max != t_last): elif (t_max and t_last and cl_last and cl_max ) and (t_max != t_last):
nyl = t_last.normal().y nyl = -t_last.normal().y
nzl = t_last.normal().z nzl = t_last.normal().z
nym = t_max.normal().y nym = -t_max.normal().y
nzm = t_max.normal().z nzm = t_max.normal().z
yl = cl_last.y yl = cl_last.y
zl = cl_last.z zl = cl_last.z
ym = cl_max.y ym = cl_max.y
zm = cl_max.z zm = cl_max.z
try: (Y,Z) = intersect_lines(yl, zl, nyl, nzl, ym, zm, nym, nzm)
if Y and yl < Y and Y < ym and (Z > zl or Z > zm):
X = cl_last.x X = cl_last.x
Y = (zl-zm+(ym*nym/nzm+yl*nyl/nzl))/(nym/nzm+nyl/nzl) if Z<z0 or Z>z1:
Z = zl + (Y-yl)*nyl/nzm print "^", "yl=",yl,", zl=",zl,"nyl=",nyl,", nzl=",nzl,", Y=", Y, ", Z=",Z,", ym=",ym,",zm=",zm, ", nym=",nym,",nzm=",nzm
if yl > Y and Y < ym: else:
pa.append(Point(X,Y,Z)) pa.append(Point(X,Y,Z))
except:
pass
pa.append(cl_max) pa.append(cl_max)
......
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