Commit a8a1f8d3 authored by lode_leroy's avatar lode_leroy

initial import

git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@3 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 02ce3527
This diff is collapsed.
pycam - CNC Toolpath Generation in python
=========================================
Copyright (C) 2008 Lode Leroy
-----------------------------
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
See COPYING
......@@ -48,6 +48,9 @@ For visualization, install
TODO:
* Python code
** clean up module/package use, being all "import" statements
* Geometry
** intersect_torus_line
-> try to find a better implementation
......
solid box0
facet normal -0.000000 0.000000 1.000000
outer loop
vertex -4.961088 -4.824490 4.188777
vertex -0.772311 -0.635713 4.188777
vertex -4.961088 -0.635713 4.188777
endloop
endfacet
facet normal -0.000000 0.000000 1.000000
outer loop
vertex -4.961088 -4.824490 4.188777
vertex -0.772311 -4.824490 4.188777
vertex -0.772311 -0.635713 4.188777
endloop
endfacet
facet normal 0.000000 0.000000 -1.000000
outer loop
vertex -0.772311 -4.824490 0.000000
vertex -4.961088 -0.635713 0.000000
vertex -0.772311 -0.635713 0.000000
endloop
endfacet
facet normal 0.000000 0.000000 -1.000000
outer loop
vertex -0.772311 -4.824490 0.000000
vertex -4.961088 -4.824490 0.000000
vertex -4.961088 -0.635713 0.000000
endloop
endfacet
facet normal 1.000000 -0.000000 0.000000
outer loop
vertex -0.772311 -4.824490 4.188777
vertex -0.772311 -0.635713 0.000000
vertex -0.772311 -0.635713 4.188777
endloop
endfacet
facet normal 1.000000 -0.000000 0.000000
outer loop
vertex -0.772311 -4.824490 4.188777
vertex -0.772311 -4.824490 0.000000
vertex -0.772311 -0.635713 0.000000
endloop
endfacet
facet normal -1.000000 0.000000 0.000000
outer loop
vertex -4.961088 -4.824490 0.000000
vertex -4.961088 -0.635713 4.188777
vertex -4.961088 -0.635713 0.000000
endloop
endfacet
facet normal -1.000000 0.000000 0.000000
outer loop
vertex -4.961088 -4.824490 0.000000
vertex -4.961088 -4.824490 4.188777
vertex -4.961088 -0.635713 4.188777
endloop
endfacet
facet normal 0.000000 1.000000 0.000000
outer loop
vertex -4.961088 -0.635713 4.188777
vertex -0.772311 -0.635713 0.000000
vertex -4.961088 -0.635713 0.000000
endloop
endfacet
facet normal 0.000000 1.000000 0.000000
outer loop
vertex -4.961088 -0.635713 4.188777
vertex -0.772311 -0.635713 4.188777
vertex -0.772311 -0.635713 0.000000
endloop
endfacet
facet normal 0.000000 -1.000000 0.000000
outer loop
vertex -4.961088 -4.824490 0.000000
vertex -0.772311 -4.824490 4.188777
vertex -4.961088 -4.824490 4.188777
endloop
endfacet
facet normal 0.000000 -1.000000 0.000000
outer loop
vertex -4.961088 -4.824490 0.000000
vertex -0.772311 -4.824490 0.000000
vertex -0.772311 -4.824490 4.188777
endloop
endfacet
endsolid box0
solid box1
facet normal 0.707143 -0.408041 0.577452
outer loop
vertex 2.563112 -5.599983 2.267282
vertex 5.339321 -3.997340 0.000022
vertex 2.562797 -2.393577 4.533387
endloop
endfacet
facet normal 0.707143 -0.408041 0.577452
outer loop
vertex 5.339321 -3.997340 0.000022
vertex 5.339006 -0.790934 2.266127
vertex 2.562797 -2.393577 4.533387
endloop
endfacet
facet normal -0.707143 0.408041 -0.577452
outer loop
vertex -0.213384 -3.997869 0.000000
vertex -0.213699 -0.791464 2.266105
vertex 2.562824 -2.395226 -2.267260
endloop
endfacet
facet normal -0.707143 0.408041 -0.577452
outer loop
vertex -0.213699 -0.791464 2.266105
vertex 2.562510 0.811179 -0.001155
vertex 2.562824 -2.395226 -2.267260
endloop
endfacet
facet normal 0.707070 0.408176 -0.577446
outer loop
vertex 5.339006 -0.790934 2.266127
vertex 2.562824 -2.395226 -2.267260
vertex 2.562510 0.811179 -0.001155
endloop
endfacet
facet normal 0.707070 0.408176 -0.577446
outer loop
vertex 5.339006 -0.790934 2.266127
vertex 5.339321 -3.997340 0.000022
vertex 2.562824 -2.395226 -2.267260
endloop
endfacet
facet normal -0.707070 -0.408176 0.577446
outer loop
vertex -0.213384 -3.997869 0.000000
vertex 2.562797 -2.393577 4.533387
vertex -0.213699 -0.791464 2.266105
endloop
endfacet
facet normal -0.707070 -0.408176 0.577446
outer loop
vertex -0.213384 -3.997869 0.000000
vertex 2.563112 -5.599983 2.267282
vertex 2.562797 -2.393577 4.533387
endloop
endfacet
facet normal -0.000080 0.816637 0.577152
outer loop
vertex -0.213699 -0.791464 2.266105
vertex 5.339006 -0.790934 2.266127
vertex 2.562510 0.811179 -0.001155
endloop
endfacet
facet normal -0.000080 0.816637 0.577152
outer loop
vertex -0.213699 -0.791464 2.266105
vertex 2.562797 -2.393577 4.533387
vertex 5.339006 -0.790934 2.266127
endloop
endfacet
facet normal 0.000080 -0.816637 -0.577152
outer loop
vertex -0.213384 -3.997869 0.000000
vertex 5.339321 -3.997340 0.000022
vertex 2.563112 -5.599983 2.267282
endloop
endfacet
facet normal 0.000080 -0.816637 -0.577152
outer loop
vertex -0.213384 -3.997869 0.000000
vertex 2.562824 -2.395226 -2.267260
vertex 5.339321 -3.997340 0.000022
endloop
endfacet
endsolid box1
solid box0
facet normal -0.000000 0.000000 1.000000
outer loop
vertex -4.961088 -4.824490 4.188777
vertex -0.772311 -0.635713 4.188777
vertex -4.961088 -0.635713 4.188777
endloop
endfacet
facet normal -0.000000 0.000000 1.000000
outer loop
vertex -4.961088 -4.824490 4.188777
vertex -0.772311 -4.824490 4.188777
vertex -0.772311 -0.635713 4.188777
endloop
endfacet
facet normal 0.000000 0.000000 -1.000000
outer loop
vertex -0.772311 -4.824490 0.000000
vertex -4.961088 -0.635713 0.000000
vertex -0.772311 -0.635713 0.000000
endloop
endfacet
facet normal 0.000000 0.000000 -1.000000
outer loop
vertex -0.772311 -4.824490 0.000000
vertex -4.961088 -4.824490 0.000000
vertex -4.961088 -0.635713 0.000000
endloop
endfacet
facet normal 1.000000 -0.000000 0.000000
outer loop
vertex -0.772311 -4.824490 4.188777
vertex -0.772311 -0.635713 0.000000
vertex -0.772311 -0.635713 4.188777
endloop
endfacet
facet normal 1.000000 -0.000000 0.000000
outer loop
vertex -0.772311 -4.824490 4.188777
vertex -0.772311 -4.824490 0.000000
vertex -0.772311 -0.635713 0.000000
endloop
endfacet
facet normal -1.000000 0.000000 0.000000
outer loop
vertex -4.961088 -4.824490 0.000000
vertex -4.961088 -0.635713 4.188777
vertex -4.961088 -0.635713 0.000000
endloop
endfacet
facet normal -1.000000 0.000000 0.000000
outer loop
vertex -4.961088 -4.824490 0.000000
vertex -4.961088 -4.824490 4.188777
vertex -4.961088 -0.635713 4.188777
endloop
endfacet
facet normal 0.000000 1.000000 0.000000
outer loop
vertex -4.961088 -0.635713 4.188777
vertex -0.772311 -0.635713 0.000000
vertex -4.961088 -0.635713 0.000000
endloop
endfacet
facet normal 0.000000 1.000000 0.000000
outer loop
vertex -4.961088 -0.635713 4.188777
vertex -0.772311 -0.635713 4.188777
vertex -0.772311 -0.635713 0.000000
endloop
endfacet
facet normal 0.000000 -1.000000 0.000000
outer loop
vertex -4.961088 -4.824490 0.000000
vertex -0.772311 -4.824490 4.188777
vertex -4.961088 -4.824490 4.188777
endloop
endfacet
facet normal 0.000000 -1.000000 0.000000
outer loop
vertex -4.961088 -4.824490 0.000000
vertex -0.772311 -4.824490 0.000000
vertex -0.772311 -4.824490 4.188777
endloop
endfacet
endsolid box0
solid box1
facet normal 0.707143 -0.408041 0.577452
outer loop
vertex 2.563112 -5.599983 2.267282
vertex 5.339321 -3.997340 0.000022
vertex 2.562797 -2.393577 4.533387
endloop
endfacet
facet normal 0.707143 -0.408041 0.577452
outer loop
vertex 5.339321 -3.997340 0.000022
vertex 5.339006 -0.790934 2.266127
vertex 2.562797 -2.393577 4.533387
endloop
endfacet
facet normal -0.707143 0.408041 -0.577452
outer loop
vertex -0.213384 -3.997869 0.000000
vertex -0.213699 -0.791464 2.266105
vertex 2.562824 -2.395226 -2.267260
endloop
endfacet
facet normal -0.707143 0.408041 -0.577452
outer loop
vertex -0.213699 -0.791464 2.266105
vertex 2.562510 0.811179 -0.001155
vertex 2.562824 -2.395226 -2.267260
endloop
endfacet
facet normal 0.707070 0.408176 -0.577446
outer loop
vertex 5.339006 -0.790934 2.266127
vertex 2.562824 -2.395226 -2.267260
vertex 2.562510 0.811179 -0.001155
endloop
endfacet
facet normal 0.707070 0.408176 -0.577446
outer loop
vertex 5.339006 -0.790934 2.266127
vertex 5.339321 -3.997340 0.000022
vertex 2.562824 -2.395226 -2.267260
endloop
endfacet
facet normal -0.707070 -0.408176 0.577446
outer loop
vertex -0.213384 -3.997869 0.000000
vertex 2.562797 -2.393577 4.533387
vertex -0.213699 -0.791464 2.266105
endloop
endfacet
facet normal -0.707070 -0.408176 0.577446
outer loop
vertex -0.213384 -3.997869 0.000000
vertex 2.563112 -5.599983 2.267282
vertex 2.562797 -2.393577 4.533387
endloop
endfacet
facet normal -0.000080 0.816637 0.577152
outer loop
vertex -0.213699 -0.791464 2.266105
vertex 5.339006 -0.790934 2.266127
vertex 2.562510 0.811179 -0.001155
endloop
endfacet
facet normal -0.000080 0.816637 0.577152
outer loop
vertex -0.213699 -0.791464 2.266105
vertex 2.562797 -2.393577 4.533387
vertex 5.339006 -0.790934 2.266127
endloop
endfacet
facet normal 0.000080 -0.816637 -0.577152
outer loop
vertex -0.213384 -3.997869 0.000000
vertex 5.339321 -3.997340 0.000022
vertex 2.563112 -5.599983 2.267282
endloop
endfacet
facet normal 0.000080 -0.816637 -0.577152
outer loop
vertex -0.213384 -3.997869 0.000000
vertex 2.562824 -2.395226 -2.267260
vertex 5.339321 -3.997340 0.000022
endloop
endfacet
endsolid box1
This diff is collapsed.
This diff is collapsed.
solid model0
facet normal 0.596285 0.298142 -0.745356
outer loop
vertex -2.000000 1.000000 4.000000
vertex -3.000000 -2.000000 2.000000
vertex -5.000000 2.000000 2.000000
endloop
endfacet
facet normal -0.596285 -0.298142 0.745356
outer loop
vertex -5.000000 2.000000 2.000000
vertex -3.000000 -2.000000 2.000000
vertex -2.000000 1.000000 4.000000
endloop
endfacet
facet normal 0.520266 0.346844 -0.780399
outer loop
vertex 0.000000 -2.000000 4.000000
vertex -3.000000 -2.000000 2.000000
vertex -2.000000 1.000000 4.000000
endloop
endfacet
facet normal -0.520266 -0.346844 0.780399
outer loop
vertex -2.000000 1.000000 4.000000
vertex -3.000000 -2.000000 2.000000
vertex 0.000000 -2.000000 4.000000
endloop
endfacet
facet normal 0.534522 0.267261 -0.801784
outer loop
vertex 0.000000 -2.000000 4.000000
vertex -2.000000 -4.000000 2.000000
vertex -3.000000 -2.000000 2.000000
endloop
endfacet
facet normal -0.534522 -0.267261 0.801784
outer loop
vertex -3.000000 -2.000000 2.000000
vertex -2.000000 -4.000000 2.000000
vertex 0.000000 -2.000000 4.000000
endloop
endfacet
facet normal 0.000000 0.707107 -0.707107
outer loop
vertex 0.000000 -2.000000 4.000000
vertex 2.000000 -4.000000 2.000000
vertex -2.000000 -4.000000 2.000000
endloop
endfacet
facet normal 0.000000 -0.707107 0.707107
outer loop
vertex -2.000000 -4.000000 2.000000
vertex 2.000000 -4.000000 2.000000
vertex 0.000000 -2.000000 4.000000
endloop
endfacet
facet normal -0.486664 0.324443 -0.811107
outer loop
vertex 0.000000 -2.000000 4.000000
vertex 4.000000 -1.000000 2.000000
vertex 2.000000 -4.000000 2.000000
endloop
endfacet
facet normal 0.486664 -0.324443 0.811107
outer loop
vertex 2.000000 -4.000000 2.000000
vertex 4.000000 -1.000000 2.000000
vertex 0.000000 -2.000000 4.000000
endloop
endfacet
facet normal -0.486664 0.324443 -0.811107
outer loop
vertex 2.000000 1.000000 4.000000
vertex 4.000000 -1.000000 2.000000
vertex 0.000000 -2.000000 4.000000
endloop
endfacet
facet normal 0.486664 -0.324443 0.811107
outer loop
vertex 0.000000 -2.000000 4.000000
vertex 4.000000 -1.000000 2.000000
vertex 2.000000 1.000000 4.000000
endloop
endfacet
facet normal -0.588348 0.196116 -0.784465
outer loop
vertex 2.000000 1.000000 4.000000
vertex 5.000000 2.000000 2.000000
vertex 4.000000 -1.000000 2.000000
endloop
endfacet
facet normal 0.588348 -0.196116 0.784465
outer loop
vertex 4.000000 -1.000000 2.000000
vertex 5.000000 2.000000 2.000000
vertex 2.000000 1.000000 4.000000
endloop
endfacet
facet normal -0.132164 -0.792982 -0.594737
outer loop
vertex 2.000000 1.000000 4.000000
vertex -1.000000 3.000000 2.000000
vertex 5.000000 2.000000 2.000000
endloop
endfacet
facet normal 0.132164 0.792982 0.594737
outer loop
vertex 5.000000 2.000000 2.000000
vertex -1.000000 3.000000 2.000000
vertex 2.000000 1.000000 4.000000
endloop
endfacet
facet normal 0.000000 -0.707107 -0.707107
outer loop
vertex -2.000000 1.000000 4.000000
vertex -1.000000 3.000000 2.000000
vertex 2.000000 1.000000 4.000000
endloop
endfacet
facet normal 0.000000 0.707107 0.707107
outer loop
vertex 2.000000 1.000000 4.000000
vertex -1.000000 3.000000 2.000000
vertex -2.000000 1.000000 4.000000
endloop
endfacet
facet normal 0.184900 -0.739600 -0.647150
outer loop
vertex -2.000000 1.000000 4.000000
vertex -5.000000 2.000000 2.000000
vertex -1.000000 3.000000 2.000000
endloop
endfacet
facet normal -0.184900 0.739600 0.647150
outer loop
vertex -1.000000 3.000000 2.000000
vertex -5.000000 2.000000 2.000000
vertex -2.000000 1.000000 4.000000
endloop
endfacet
facet normal 0.000000 0.000000 -1.000000
outer loop
vertex -2.000000 1.000000 4.000000
vertex 2.000000 1.000000 4.000000
vertex 0.000000 -2.000000 4.000000
endloop
endfacet
facet normal 0.000000 0.000000 1.000000
outer loop
vertex 0.000000 -2.000000 4.000000
vertex 2.000000 1.000000 4.000000
vertex -2.000000 1.000000 4.000000
endloop
endfacet
endsolid model0
#!/usr/bin/python
import sys
sys.path.insert(0,'.')
from pycam.Geometry import *
from pycam.Cutters.CylindricalCutter import *
from pycam.Gui.Visualization import ShowTestScene
if __name__ == "__main__":
dir = Point(0,0,-1)
#c = CylindricalCutter(1, Point(0,0,6))
c = CylindricalCutter(1, Point(2,0,6))
#c = CylindricalCutter(1, Point(-2.2,0.2,6))
#c = CylindricalCutter(1, Point(-1.7,-0.2,6))
print "c=", c
#t = Triangle(Point(-3,0,2), Point(2,2,3), Point(2,-2,4))
#t = Triangle(Point(-2,0,2), Point(2,-1,4), Point(2,1,3))
#t = Triangle(Point(2,0,4), Point(2,-1,2), Point(2,1,2))
#t = Triangle(Point(2,0,4), Point(2,1,2), Point(2,-1,2))
#t = Triangle(Point(-3,0,4), Point(2,2,2), Point(2,-2,2))
t = Triangle(Point(-3,0,2.5), Point(3,0,2.5), Point(0,1,1.5))
print "t=", t
if False:
print "plane:"
(cl_p,ccp_p,cp_p,d_p) = c.intersect_circle_plane(dir,t)
print "ccp=", ccp_p
print "cp=", cp_p
print "cl=", cl_p
print "d=", d_p
print "triangle:"
(cl_t,d_t) = c.intersect_circle_triangle(dir,t)
print "cl=", cl_t
print "d=", d_t
print "point:"
(cl_v,ccp_v,cp_v,d_v) = c.intersect_circle_point(dir,t.p1)
print "ccp=", ccp_v
print "cp=", cp_v
print "cl=", cl_v
print "d=", d_v
l = Line(t.p2,t.p3)
print "line:", l
(cl_l,ccp_l,cp_l,d_l) = c.intersect_circle_line(dir,l)
print "ccp=", ccp_l
print "cp=", cp_l
print "cl=", cl_l
print "d=", d_l
print "edge:", l
(cl_e,d_e) = c.intersect_circle_edge(dir,l)
print "cl=", cl_e
print "d=", d_e
print "piece:"
(cl,d) = c.intersect(dir,t)
print "cl=", cl
if False:
samples = 50
x0 = -5.0
x1 = +5.0
y0 = -5.0
y1 = +5.0
z = 10
dir = Point(0,0,-1)
pathlist = []
for i in range(0,samples):
x = x0 + i * ((x1-x0) / samples)
p = Path()
for j in range(0,samples):
y = y0 + j * ((y1-y0) / samples)
c.moveto(Point(x,y,z))
cl = c.drop(t)
if cl:
p.append(cl)
else:
p.append(Point(x,y,0))
pathlist.append(p)
c.moveto(Point(x0,y0,z))
ShowTestScene(t, c, pathlist)
if True:
samples = 50
layers = 10
x0 = -5.0
x1 = +5.0
y0 = -5.0
y1 = +5.0
z0 = 0
z1 = 4
dir = Point(1,0,0)
pathlist = []
for i in range(0, layers):
z = z1-i*float(z1-z0)/layers
for j in range(0,samples):
y = y0 + j * ((y1-y0) / samples)
p = Point(x0,y,z)
c.moveto(p)
(cl,l) = c.intersect(dir,t)
if cl:
p = Path()
#p.append(c.center)
#p.append(ccp)
#p.append(cp)
p.append(cl)
p.append(cl.sub(dir.mul(l)))
pathlist.append(p)
c.moveto(Point(x0,y0,z1))
ShowTestScene(t, c, pathlist)
#!/usr/bin/python
import sys
sys.path.insert(0,'.')
from pycam.Geometry import *
from pycam.Cutters.SphericalCutter import *
from pycam.Cutters.CylindricalCutter import *
from pycam.Cutters.ToroidalCutter import *
from pycam.Gui.Visualization import ShowTestScene
from pycam.Importers.TestModel import TestModel
from pycam.PathGenerators.DropCutter import DropCutter
from pycam.Exporters.SimpleGCodeExporter import SimpleGCodeExporter
if __name__ == "__main__":
c = SphericalCutter(1, Point(0,0,7))
#c = CylindricalCutter(1, Point(0,0,7))
#c = ToroidalCutter(1, 0.25, Point(0,0,7))
print "c=", c
model = TestModel()
if True:
samples = 20
lines = 20
x0 = -7.0
x1 = +7.0
y0 = -7.0
y1 = +7.0
z0 = 0
z1 = 4
dx = (x1-x0)/samples
dy = (y1-y0)/lines
pg = DropCutter(c, model)
pathlist = pg.GenerateToolPath(x0, x1, y0, y1, z0, z1, dx, dy)
g = SimpleGCodeExporter("cutter2.nc", z1)
g.AddPathList(pathlist)
g.close()
ShowTestScene(model, c, pathlist)
#!/usr/bin/python
import sys
sys.path.insert(0,'.')
from pycam.Exporters.MGEDExporter import MGEDExporter
from pycam.Importers.TestModel import TestModel
model = TestModel()
file = MGEDExporter("TestModel.txt")
file.AddModel(model)
file.close()
This diff is collapsed.
#!/usr/bin/python
import sys
sys.path.insert(0,'.')
from pycam.Geometry import *
from pycam.Cutters.SphericalCutter import *
from pycam.Cutters.CylindricalCutter import *
from pycam.Cutters.ToroidalCutter import *
from pycam.Gui.Visualization import ShowTestScene
from pycam.Importers import STLImporter
from pycam.PathGenerators.PushCutter import PushCutter
from pycam.PathProcessors import *
from pycam.Exporters.SimpleGCodeExporter import SimpleGCodeExporter
if __name__ == "__main__":
c = SphericalCutter(0.1, Point(0,0,7))
#c = CylindricalCutter(1, Point(0,0,7))
#c = ToroidalCutter(1, 0.25, Point(0,0,7))
print "c=", c
#model = TestModel()
#model = STLImporter.ImportModel("Samples/STL/Box0.stl")
#model = STLImporter.ImportModel("Samples/STL/Box1.stl")
model = STLImporter.ImportModel("Samples/STL/Box0+1.stl")
#model = Model()
#model.append(Triangle(Point(0,0,0),Point(0,5,4),Point(0,-5,4)))
#model.append(Triangle(Point(2,0,0),Point(2,-5,4),Point(2,5,4)))
if True:
lines = 20
layers = 4
x0 = -7.0
x1 = +7.0
y0 = -7.0
y1 = +7.0
z0 = 2.0
z1 = 4.0
pc = PushCutter(c, model, SimpleCutter())
#pc = PushCutter(c, model, ZigZagCutter())
#pc = PushCutter(c, model, PolygonCutter())
dx = 0
if lines>1:
dy = float(y1-y0)/(lines-1)
else:
dy = INFINITE
if layers>1:
dz = float(z1-z0)/(layers-1)
else:
dz = INFINITE
pathlist = pc.GenerateToolPath(x0,x1,y0,y1,z0,z1,dx,dy,dz)
c.moveto(Point(x0,y0,z0))
ShowTestScene(model, c, pathlist)
#!/usr/bin/python
import sys
sys.path.insert(0,'.')
from pycam.Importers import STLImporter
from pycam.Gui.Visualization import ShowTestScene
model = STLImporter.ImportModel("Samples/STL/SampleScene.stl")
ShowTestScene(model)
#!/usr/bin/python
import sys
sys.path.insert(0,'.')
import math
from pycam.Geometry import *
from pycam.Cutters.SphericalCutter import *
from pycam.Gui.Visualization import ShowTestScene
if __name__ == "__main__":
if False:
cutter = SphericalCutter(1, Point(-10,0.5,0))
edge = Line(Point(0,0,-10),Point(0,0,10))
dir = Point(1,0,0)
print "cutter=", cutter
print "edge=", edge
print "dir=", dir
(cl,ccp,cp,d) = cutter.intersect_sphere_line(dir, edge)
print "cp=", cp
print "ccp=", ccp
print "d=", d
print "cl=", cl
exit()
if False:
cutter = SphericalCutter(1, Point(-10,0,0))
edge = Line(Point(0,-5,1),Point(3,+5,1))
dir = Point(1,-0.2,0)
print "cutter=", cutter
print "edge=", edge
print "dir=", dir
(cl,ccp,cp,d) = cutter.intersect_cylinder_line(dir, edge)
print "cp=", cp
print "ccp=", ccp
print "d=", d
print "cl=", cl
dir = Point(0,0,-1)
c = SphericalCutter(1, Point(0,0,6))
#c = SphericalCutter(1, Point(-2.2,0.2,6))
#c = SphericalCutter(1, Point(-1.7,0.5,6))
print "c=", c
t = Triangle(Point(-2,0,2), Point(2,1,3), Point(2,-1,4))
#t = Triangle(Point(-2,0,2), Point(2,-1,4), Point(2,1,3))
#t = Triangle(Point(2,0,4), Point(2,-1,2), Point(2,1,2))
print "t=", t
if False:
(cl_p,ccp_p,cp_p,d_p) = c.intersect_sphere_plane(dir,t)
print "ccp=", ccp_p
print "cp=", cp_p
print "cl=", cl_p
print "d=", d_p
(cl_v,ccp_v,cp_v,d_v) = c.intersect_sphere_point(dir,t.p1)
print "ccp=", ccp_v
print "cp=", cp_v
print "cl=", cl_v
print "d=", d_v
(cl_e,ccp_e,cp_e,d_e) = c.intersect_sphere_line(dir,Line(t.p1,t.p2))
print "ccp=", ccp_e
print "cp=", cp_e
print "cl=", cl_e
print "d=", d_e
(cl,d) = c.intersect(dir,t)
print "cl=", cl
if False:
samples = 50
x0 = -5.0
x1 = +5.0
y0 = -5.0
y1 = +5.0
z = 10
pathlist = []
for i in range(0,samples):
x = x0 + i * ((x1-x0) / samples)
p = Path()
for j in range(0,samples):
y = y0 + j * ((y1-y0) / samples)
c.moveto(Point(x,y,z))
cl = c.drop(t)
if cl:
p.append(cl)
else:
p.append(Point(x,y,0))
pathlist.append(p)
c.moveto(Point(x0,y0,z))
ShowTestScene(t, c, pathlist)
if True:
samples = 50
layers = 10
x0 = -5.0
x1 = +5.0
y0 = -3.0
y1 = +3.0
z0 = 0
z1 = 3
dir = Point(1,0,0)
pathlist = []
for i in range(0, layers):
z = z1-i*float(z1-z0)/layers
for j in range(0,samples):
y = y0 + j * ((y1-y0) / samples)
c.moveto(Point(x0,y,z))
(cl,l) = c.intersect(dir,t)
if cl:
p = Path()
#p.append(c.center)
#p.append(ccp)
#p.append(cp)
p.append(cl)
p.append(cl.sub(dir.mul(l)))
pathlist.append(p)
c.moveto(Point(x0,y0,z))
ShowTestScene(t, c, pathlist)
#!/usr/bin/python
import sys
sys.path.insert(0,'.')
from pycam.Geometry import *
from pycam.Cutters.ToroidalCutter import *
from pycam.Gui.Visualization import ShowTestScene
import math
if __name__ == "__main__":
if False:
cutter = ToroidalCutter(1, 0.25, Point(-10,0.5,0))
edge = Line(Point(0,0,-10),Point(0,0,10))
dir = Point(1,0,0)
print "cutter=", cutter
print "edge=", edge
print "dir=", dir
(cl,ccp,cp,d) = cutter.intersect_sphere_line(dir, edge)
print "cp=", cp
print "ccp=", ccp
print "d=", d
print "cl=", cl
exit()
if False:
cutter = ToroidalCutter(1, 0.25, Point(-10,0,0))
edge = Line(Point(0,-5,1),Point(3,+5,1))
dir = Point(1,-0.2,0)
print "cutter=", cutter
print "edge=", edge
print "dir=", dir
(cl,ccp,cp,d) = cutter.intersect_cylinder_line(dir, edge)
print "cp=", cp
print "ccp=", ccp
print "d=", d
print "cl=", cl
#dir = Point(0,0,-1)
#c = ToroidalCutter(1, 0.25, Point(0,0,6))
#c = ToroidalCutter(1, 0.25, Point(-2.2,0.2,6))
#c = ToroidalCutter(1, 0.25, Point(-1.7,0.5,6))
dir = Point(1,0,0)
c = ToroidalCutter(1, 0.25, Point(-10,0.1,1.9))
print "c=", c
t = Triangle(Point(-2,0,2), Point(2,1,3), Point(2,-1,4))
print "t=", t
if False:
if False:
(cl_p,ccp_p,cp_p,d_p) = c.intersect_torus_plane(dir,t)
print "ccp=", ccp_p
print "cp=", cp_p
print "cl=", cl_p
print "d=", d_p
if False:
p = t.p1
(cl_v,ccp_v,cp_v,d_v) = c.intersect_torus_point(dir,p)
print "ccp=", ccp_v
print "cp=", cp_v
print "cl=", cl_v
print "d=", d_v
if False:
e = Line(t.p1,t.p2)
(cl_e,ccp_e,cp_e,d_e) = c.intersect_torus_line(dir,e)
print "ccp=", ccp_e
print "cp=", cp_e
print "cl=", cl_e
print "d=", d_e
if False:
(cl,d) = c.intersect(dir,t)
print "cl=", cl
if False:
samples = 50
x0 = -5.0
x1 = +5.0
y0 = -5.0
y1 = +5.0
z = 10
pathlist = []
for i in range(0,samples):
x = x0 + i * ((x1-x0) / samples)
p = Path()
for j in range(0,samples):
y = y0 + j * ((y1-y0) / samples)
c.moveto(Point(x,y,z))
cl = c.drop(t)
if cl:
p.append(cl)
else:
p.append(Point(x,y,0))
pathlist.append(p)
c.moveto(Point(x0,y0,z))
ShowTestScene(t, c, pathlist)
if True:
samples = 100
layers = 10
x0 = -5.0
x1 = +5.0
y0 = -5.0
y1 = +5.0
z0 = 0
z1 = 3
dir = Point(1,0,0)
pathlist = []
for i in range(0, layers):
z = z1-i*float(z1-z0)/layers
for j in range(0,samples):
y = y0 + j * ((y1-y0) / samples)
c.moveto(Point(x0,y,z))
(cl,l) = c.intersect(dir,t)
if cl:
p = Path()
#p.append(c.center)
#p.append(ccp)
#p.append(cp)
p.append(cl)
p.append(cl.sub(dir.mul(l)))
pathlist.append(p)
c.moveto(Point(x0,y0,z))
ShowTestScene(t, c, pathlist)
#!/usr/bin/python
import sys
sys.path.insert(0,'.')
from pycam.Geometry.TriangleKdtree import *
from pycam.Geometry.Model import Model
from pycam.Importers.TestModel import TestModel
def comb_tomged(f, triangles, name, color):
comb = ""
for t in triangles:
comb += " u triangle%d" % t.id
if len(comb)>512:
f.write("comb "+name+comb+"\n")
comb = ""
if len(comb)>0:
f.write("comb "+name+comb+"\n")
f.write("mater " + name + " del " + color + " 1\n")
print "# get model"
testmodel = TestModel()
print "# subdivide"
model = testmodel.subdivide(5)
print "# build kdtree"
kdtree = BuildKdtree2d(model.triangles(), 2, 0.1)
#print "#kdtree=",kdtree
x = 2
y = 2
r = 0.1
minx = x-r
miny = y-r
maxx = x+r
maxy = y+r
print "# query kdtree"
ResetKdtree2dStats(False)
tests = SearchKdtree2d(kdtree, minx, maxx, miny, maxy)
print "# query kdtree"
ResetKdtree2dStats(True)
hits = SearchKdtree2d(kdtree, minx, maxx, miny, maxy)
#print "# hits=%d / tests=%d" % GetKdtree2dStats(), "/ triangles=%d" % len(model.triangles())
print "# hits=%d " % len(hits), "/ tests=%d" % len(tests), "/ triangles=%d" % len(model.triangles())
print "# write mged"
f = file("test.txt","w")
f.write("in query.s arb8 %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f\n" %
(minx, miny, 0, maxx, miny, 0, minx, maxy, 0, maxx, maxy, 0, minx, miny, 10, maxx, miny, 10, minx, maxy, 10, maxx, maxy, 10))
f.write("comb query.c u query.s\n")
f.write("mater query.c del 255 255 255 0\n")
if False:
for t in model.triangles():
f.write(t.to_mged())
comb_tomged(f, model.triangles(), "model.c", "255 0 0")
else:
for t in tests:
f.write(t.to_mged())
comb_tomged(f, tests, "tests.c", "0 255 0")
comb_tomged(f, hits, "hits.c", "0 0 255")
#print kdtree
#f.write(kdtree.to_mged(-7,-7,7,7))
f.write(SearchKdtree2d_mged(kdtree, minx, maxx, miny, maxy,-7,-7,+7,+7))
f.close()
#!/usr/bin/python
import sys
sys.path.insert(0,'.')
import math
from pycam.Geometry import *
if __name__ == "__main__":
p1 = Point(1,0,0)
p2 = Point(0,1,0)
p3 = Point(0,0,1)
print "p1=" + str(p1);
print "p2=" + str(p2);
print "p3=" + str(p3);
print "p2-p1=" + str(p2.sub(p1))
print "p3-p2=" + str(p3.sub(p2))
print "p1-p3=" + str(p1.sub(p3))
print "p2.p1=" + str(p2.dot(p1))
print "p3.p2=" + str(p3.dot(p2))
print "p1.p3=" + str(p1.dot(p3))
print "p1xp2=" + str(p1.cross(p2))
print "p2xp3=" + str(p2.cross(p3))
print "p3xp1=" + str(p3.cross(p1))
t = Triangle(p1,p2,p3)
print t
t.calc_circumcircle()
print "circ(t) = %s@%s" % (t.radius,t.center())
f = file("triangle0.txt","w")
f.write(t.to_mged(sphere=True))
f.close()
#!/usr/bin/python
import sys
sys.path.insert(0,'.')
from pycam.Gui.Visualization import Visualization
from pycam.Importers.TestModel import TestModel
model = TestModel()
def DrawScene():
model.to_OpenGL()
Visualization("VisualizationTest", DrawScene)
import sys
import os
sys.path.insert(0, os.path.join(sys.prefix, "PyOpenGL-3.0.0b5-py2.5.egg"))
sys.path.insert(0, os.path.join(sys.prefix, "setuptools-0.6c8-py2.5.egg"))
from pycam.Gui.SimpleGui import SimpleGui
from pycam.Importers.TestModel import TestModel
gui = SimpleGui()
gui.model = TestModel()
gui.mainloop()
import pycam.Geometry
from pycam.Geometry import *
from pycam.Geometry.utils import *
from pycam.Geometry.utils import *
from math import sqrt
class BaseCutter:
id = 0
def __init__(self, location, radius):
self.location = location
self.id = BaseCutter.id
BaseCutter.id += 1
self.radius = radius
self.radiussq = radius*radius
self.minx = location.x-radius
self.maxx = location.x+radius
self.miny = location.y-radius
self.maxy = location.y+radius
def __repr__(self):
return "BaseCutter"
def to_mged(self):
return ""
def moveto(self, location):
self.location = location
self.minx = location.x-self.radius
self.maxx = location.x+self.radius
self.miny = location.y-self.radius
self.maxy = location.y+self.radius
def intersect(self, direction, triangle):
return (None, None, None, INFINITE)
def drop(self, triangle):
# check bounding box collision
if self.minx > triangle.maxx():
return None
if self.maxx < triangle.minx():
return None
if self.miny > triangle.maxy():
return None
if self.maxy < triangle.miny():
return None
# check bounding sphere collision
c = triangle.center()
if sqr(c.x-self.location.x)+sqr(c.y-self.location.y)>self.radiussq+self.radius*triangle.radius()+triangle.radiussq():
return None
(cl,d)= self.intersect(Point(0,0,-1), triangle)
return cl
def push(self, dx, dy, triangle):
# check bounding box collision
if dx == 0:
if self.miny > triangle.maxy():
return None
if self.maxy < triangle.miny():
return None
if dy == 0:
if self.minx > triangle.maxx():
return None
if self.maxx < triangle.minx():
return None
if triangle.maxz()<self.location.z:
return None
# check bounding sphere collision
c = triangle.center()
d = (c.x-self.location.x)*dy-(c.y-self.location.y)*dx
t = self.radius + triangle.radius()
if d < -t or d > t:
return None
(cl,d)= self.intersect(Point(dx,dy,0), triangle)
return cl
import pycam.Geometry
from pycam.Geometry import *
from pycam.Geometry.utils import *
from pycam.Geometry.intersection import *
from pycam.Cutters.BaseCutter import BaseCutter
from math import sqrt
try:
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
except:
pass
class CylindricalCutter(BaseCutter):
def __init__(self, radius, location=Point(0,0,0), height=10):
BaseCutter.__init__(self, location, radius)
self.height = height
self.axis = Point(0,0,1)
self.center = location
def __repr__(self):
return "CylindricalCutter<%s,%s>" % (self.location,self.radius)
def to_mged(self):
s = ""
s += "in cutter%d_cyl.s rcc"% (self.id)
s += " %f %f %f 0 0 %f %f" % (self.location.x, self.location.y, self.location.z, self.height, self.radius)
s += "\n"
s += "comb cutter%d_cyl.c u cutter%d_cyl.s\n" % (self.id, self.id)
s += "r cutter%d.r u cutter%d_cyl.c\n" % (self.id, self.id)
return s
def to_OpenGL(self):
glPushMatrix()
glTranslate(self.center.x, self.center.y, self.center.z)
if not hasattr(self,"_cylinder"):
self._cylinder = gluNewQuadric()
gluCylinder(self._cylinder, self.radius, self.radius, self.height, 10, 10)
if not hasattr(self,"_disk"):
self._disk = gluNewQuadric()
gluDisk(self._disk, 0, self.radius, 10, 10)
glPopMatrix()
def moveto(self, location):
BaseCutter.moveto(self, location)
self.center = location
def intersect_circle_plane(self, direction, triangle):
(ccp,cp,d) = intersect_circle_plane(self.center, self.radius, direction, triangle)
if ccp:
cl = cp.add(self.location.sub(ccp))
return (cl,ccp,cp,d)
return (None, None, None, INFINITE)
def intersect_circle_triangle(self, direction, triangle):
(cl,ccp,cp,d) = self.intersect_circle_plane(direction, triangle)
if cp and triangle.point_inside(cp):
return (cl,d)
return (None,INFINITE)
def intersect_circle_point(self, direction, point):
(ccp,cp,l) = intersect_circle_point(self.center, self.axis, self.radius, self.radiussq, direction, point)
if ccp:
cl = cp.add(self.location.sub(ccp))
return (cl,ccp,cp,l)
return (None,None,None,INFINITE)
def intersect_circle_vertex(self, direction, point):
(cl,ccp,cp,l) = self.intersect_circle_point(direction, point)
return (cl,l)
def intersect_circle_line(self, direction, edge):
(ccp,cp,l) = intersect_circle_line(self.center, self.axis, self.radius, self.radiussq, direction, edge)
if ccp:
cl = cp.add(self.location.sub(ccp))
return (cl,ccp,cp,l)
return (None,None,None,INFINITE)
def intersect_circle_edge(self, direction, edge):
(cl,ccp,cp,l) = self.intersect_circle_line(direction, edge)
if cp:
# check if the contact point is between the endpoints
m = cp.sub(edge.p1).dot(edge.dir())
if m<0 or m>edge.len():
return (None,INFINITE)
return (cl,l)
def intersect_cylinder_point(self, direction, point):
(ccp,cp,l) = intersect_cylinder_point(self.center, self.axis, self.radius, self.radiussq, direction, point)
# offset intersection
if ccp:
cl = cp.add(self.location.sub(ccp))
return (cl,ccp,cp,l)
return (None, None, None, INFINITE)
def intersect_cylinder_vertex(self, direction, point):
(cl,ccp,cp,l) = self.intersect_cylinder_point(direction, point)
if ccp and ccp.z < self.center.z:
return (None, INFINITE)
return (cl, l)
def intersect_cylinder_line(self, direction, edge):
(ccp,cp,l) = intersect_cylinder_line(self.center, self.axis, self.radius, self.radiussq, direction, edge)
# offset intersection
if ccp:
cl = cp.add(self.location.sub(ccp))
return (cl,ccp,cp,l)
return (None,None,None,INFINITE)
def intersect_cylinder_edge(self, direction, edge):
(cl,ccp,cp,l) = self.intersect_cylinder_line(direction, edge)
if not ccp:
return (None,INFINITE)
m = cp.sub(edge.p1).dot(edge.dir())
if m<0 or m>edge.len():
return (None,INFINITE)
if ccp.z<self.center.z:
return (None,INFINITE)
return (cl,l)
def intersect(self, direction, triangle):
(cl_t,d_t) = self.intersect_circle_triangle(direction, triangle)
(cl_p1,d_p1) = self.intersect_circle_vertex(direction, triangle.p1)
(cl_p2,d_p2) = self.intersect_circle_vertex(direction, triangle.p2)
(cl_p3,d_p3) = self.intersect_circle_vertex(direction, triangle.p3)
(cl_e1,d_e1) = self.intersect_circle_edge(direction, Line(triangle.p1,triangle.p2))
(cl_e2,d_e2) = self.intersect_circle_edge(direction, Line(triangle.p2,triangle.p3))
(cl_e3,d_e3) = self.intersect_circle_edge(direction, Line(triangle.p3,triangle.p1))
d = INFINITE
cl = None
if d_t < d:
d = d_t
cl = cl_t
if d_p1 < d:
d = d_p1
cl = cl_p1
if d_p2 < d:
d = d_p2
cl = cl_p2
if d_p3 < d:
d = d_p3
cl = cl_p3
if d_e1 < d:
d = d_e1
cl = cl_e1
if d_e2 < d:
d = d_e2
cl = cl_e2
if d_e3 < d:
d = d_e3
cl = cl_e3
if direction.x != 0 or direction.y != 0:
(cl_p1,d_p1) = self.intersect_cylinder_vertex(direction, triangle.p1)
(cl_p2,d_p2) = self.intersect_cylinder_vertex(direction, triangle.p2)
(cl_p3,d_p3) = self.intersect_cylinder_vertex(direction, triangle.p3)
(cl_e1,d_e1) = self.intersect_cylinder_edge(direction, Line(triangle.p1,triangle.p2))
(cl_e2,d_e2) = self.intersect_cylinder_edge(direction, Line(triangle.p2,triangle.p3))
(cl_e3,d_e3) = self.intersect_cylinder_edge(direction, Line(triangle.p3,triangle.p1))
if d_p1 < d:
d = d_p1
cl = cl_p1
if d_p2 < d:
d = d_p2
cl = cl_p2
if d_p3 < d:
d = d_p3
cl = cl_p3
if d_e1 < d:
d = d_e1
cl = cl_e1
if d_e2 < d:
d = d_e2
cl = cl_e2
if d_e3 < d:
d = d_e3
cl = cl_e3
return (cl,d)
import pycam.Geometry
from pycam.Geometry import *
from pycam.Geometry.utils import *
from pycam.Geometry.intersection import *
from pycam.Cutters.BaseCutter import BaseCutter
from math import sqrt
try:
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
except:
pass
class SphericalCutter(BaseCutter):
def __init__(self, radius, location=Point(0,0,0), height=10):
BaseCutter.__init__(self, location, radius)
self.height = height
self.axis = Point(0,0,1)
self.center = Point(location.x, location.y, location.z+radius)
def __repr__(self):
return "SphericalCutter<%s,%s>" % (self.location,self.radius)
def to_mged(self):
s = ""
s += "in cutter%d_sph.s sph" % (self.id)
s += " %f %f %f %f" % (self.center.x, self.center.y, self.center.z, self.radius)
s += "\n"
s += "in cutter%d_cyl.s rcc"% (self.id)
s += " %f %f %f 0 0 %f %f" % (self.center.x, self.center.y, self.center.z, self.height, self.radius)
s += "\n"
s += "comb cutter%d_sph.c u cutter%d_sph.s\n" % (self.id, self.id)
s += "comb cutter%d_cyl.c u cutter%d_cyl.s - cutter%d_sph.s\n" % (self.id, self.id, self.id)
s += "r cutter%d.r u cutter%d_cyl.c u cutter%d_sph.c\n" % (self.id, self.id, self.id)
return s
def to_OpenGL(self):
glPushMatrix()
glTranslate(self.center.x, self.center.y, self.center.z)
if not hasattr(self,"_sphere"):
self._sphere = gluNewQuadric()
gluSphere(self._sphere, self.radius, 10, 10)
if not hasattr(self,"_cylinder"):
self._cylinder = gluNewQuadric()
gluCylinder(self._cylinder, self.radius, self.radius, self.height, 10, 10)
glPopMatrix()
def moveto(self, location):
BaseCutter.moveto(self, location)
self.center = Point(location.x, location.y, location.z+self.radius)
def intersect_sphere_plane(self, direction, triangle):
(ccp,cp,d) = intersect_sphere_plane(self.center, self.radius, direction, triangle)
# offset intersection
if ccp:
cl = cp.add(self.location.sub(ccp))
return (cl,ccp,cp,d)
return (None, None, None, INFINITE)
def intersect_sphere_triangle(self, direction, triangle):
(cl,ccp,cp,d) = self.intersect_sphere_plane(direction, triangle)
if cp and triangle.point_inside(cp):
return (cl,d)
return (None,INFINITE)
def intersect_sphere_point(self, direction, point):
(ccp,cp,l) = intersect_sphere_point(self.center, self.radius, self.radiussq, direction, point)
# offset intersection
cl = self.location.add(direction.mul(l))
return (cl,ccp,cp,l)
def intersect_sphere_vertex(self, direction, point):
(cl,ccp,cp,l) = self.intersect_sphere_point(direction, point)
return (cl,l)
def intersect_sphere_line(self, direction, edge):
(ccp,cp,l) = intersect_sphere_line(self.center, self.radius, self.radiussq, direction, edge)
# offset intersection
if ccp:
cl = cp.sub(ccp.sub(self.location))
return (cl,ccp,cp,l)
return (None, None, None, INFINITE)
def intersect_sphere_edge(self, direction, edge):
(cl,ccp,cp,l) = self.intersect_sphere_line(direction, edge)
if cp:
# check if the contact point is between the endpoints
d = edge.p2.sub(edge.p1)
m = cp.sub(edge.p1).dot(d)
if m<0 or m>d.normsq():
return (None,INFINITE)
return (cl,l)
def intersect_cylinder_point(self, direction, point):
(ccp,cp,l)=intersect_cylinder_point(self.center, self.axis, self.radius, self.radiussq, direction, point)
# offset intersection
if ccp:
cl = cp.add(self.location.sub(ccp))
return (cl,ccp,cp,l)
return (None,None,None,INFINITE)
def intersect_cylinder_vertex(self, direction, point):
(cl,ccp,cp,l) = self.intersect_cylinder_point(direction, point)
if ccp and ccp.z < self.center.z:
return (None, INFINITE)
return (cl, l)
def intersect_cylinder_line(self, direction, edge):
(ccp,cp,l) = intersect_cylinder_line(self.center, self.axis, self.radius, self.radiussq, direction, edge)
# offset intersection
if ccp:
cl = self.location.add(cp.sub(ccp))
return (cl,ccp,cp,l)
return (None,None,None,INFINITE)
def intersect_cylinder_edge(self, direction, edge):
(cl,ccp,cp,l) = self.intersect_cylinder_line(direction, edge)
if not ccp:
return (None,INFINITE)
m = cp.sub(edge.p1).dot(edge.dir())
if m<0 or m>edge.len():
return (None,INFINITE)
if ccp.z<self.center.z:
return (None,INFINITE)
return (cl,l)
def intersect(self, direction, triangle):
(cl_t,d_t) = self.intersect_sphere_triangle(direction, triangle)
(cl_p1,d_p1) = self.intersect_sphere_vertex(direction, triangle.p1)
(cl_p2,d_p2) = self.intersect_sphere_vertex(direction, triangle.p2)
(cl_p3,d_p3) = self.intersect_sphere_vertex(direction, triangle.p3)
(cl_e1,d_e1) = self.intersect_sphere_edge(direction, Line(triangle.p1,triangle.p2))
(cl_e2,d_e2) = self.intersect_sphere_edge(direction, Line(triangle.p2,triangle.p3))
(cl_e3,d_e3) = self.intersect_sphere_edge(direction, Line(triangle.p3,triangle.p1))
d = INFINITE
cl = None
if d_t < d:
d = d_t
cl = cl_t
if d_p1 < d:
d = d_p1
cl = cl_p1
if d_p2 < d:
d = d_p2
cl = cl_p2
if d_p3 < d:
d = d_p3
cl = cl_p3
if d_e1 < d:
d = d_e1
cl = cl_e1
if d_e2 < d:
d = d_e2
cl = cl_e2
if d_e3 < d:
d = d_e3
cl = cl_e3
if direction.x != 0 or direction.y != 0:
(cl_p1,d_p1) = self.intersect_cylinder_vertex(direction, triangle.p1)
(cl_p2,d_p2) = self.intersect_cylinder_vertex(direction, triangle.p2)
(cl_p3,d_p3) = self.intersect_cylinder_vertex(direction, triangle.p3)
(cl_e1,d_e1) = self.intersect_cylinder_edge(direction, Line(triangle.p1,triangle.p2))
(cl_e2,d_e2) = self.intersect_cylinder_edge(direction, Line(triangle.p2,triangle.p3))
(cl_e3,d_e3) = self.intersect_cylinder_edge(direction, Line(triangle.p1,triangle.p3))
if d_p1 < d:
d = d_p1
cl = cl_p1
if d_p2 < d:
d = d_p2
cl = cl_p2
if d_p3 < d:
d = d_p3
cl = cl_p3
if d_e1 < d:
d = d_e1
cl = cl_e1
if d_e2 < d:
d = d_e2
cl = cl_e2
if d_e3 < d:
d = d_e3
cl = cl_e3
return (cl,d)
def drop_bis(self, triangle):
n = triangle.normal()
if abs(n.dot(self.axis))<epsilon:
d = triangle.p1.sub(self.center).dot(n)
if abs(d)>= self.radius-epsilon:
return None
(cl,d)= self.intersect(Point(0,0,-1), triangle)
return cl
This diff is collapsed.
list = [ "SphericalCutter", "CylindricalCutter", "ToroidalCutter" ]
__all__ = [ "BaseCutter" ] + list
from BaseCutter import BaseCutter
from SphericalCutter import SphericalCutter
from CylindricalCutter import CylindricalCutter
from ToroidalCutter import ToroidalCutter
from pycam.Geometry import *
class MGEDExporter:
def __init__(self, filename):
self.file = file(filename,"w")
def close(self):
self.file.close()
def AddCutter(self, cutter):
self.file.write(cutter.to_mged())
def AddModel(self, model):
self.file.write(model.to_mged())
def AddPath(self, path):
prev = path.points[0]
for i in range(1, len(path.points)):
next = path.points[i]
self.file.write(Line(prev,next).to_mged())
prev = next
def AddPathList(self, pathlist):
for path in pathlist:
self.AddPath(path)
from gcode import gcode
# simplistic GCode exporter
# does each run, and moves the tool to the safetyheight in between
class SimpleGCodeExporter:
def __init__(self, filename, safetyheight=7.0, homeheight=7.0):
self.file = file(filename,"w")
self.gcode = gcode(homeheight, safetyheight)
gc = self.gcode
self.file.write(gc.begin()+"\n")
self.file.write(gc.safety()+"\n")
def close(self):
gc = self.gcode
self.file.write(gc.safety()+"\n")
self.file.write(gc.end()+"\n")
self.file.close()
def AddPath(self, path):
gc = self.gcode
point = path.points[0]
self.file.write(gc.rapid(point.x,point.y,gc.safetyheight)+"\n")
for point in path.points:
self.file.write(gc.cut(point.x,point.y,point.z)+"\n")
self.file.write(gc.rapid(point.x,point.y,gc.safetyheight)+"\n")
def AddPathList(self, pathlist):
for path in pathlist:
self.AddPath(path)
def ExportPathList(filename, pathlist):
exporter = SimpleGCodeExporter(filename)
exporter.AddPathList(pathlist)
exporter.close()
list = ["MGEDExporter", "SimpleGCodeExporter"]
__all__ = list
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
from Point import *
class Plane:
id = 0
def __init__(self, p, n):
self.id = Plane.id
Plane.id += 1
self.p = p
self.n = n
def __repr__(self):
return "Plane<%s,%s>" % (self.p,self.n)
def to_mged(self):
s = ""
s += "in plane%d half"%(self.id)
s += " %f %f %f"% (self.n.x, self.n.y, self.n.z)
s += " %f "% (self.p.dot(self.n))
s += "\n"
return s
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
__all__ = ["Vizualisation"]
This diff is collapsed.
This diff is collapsed.
list = ["STLImporter"]
__all__ = ["TestModel"] + list
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
__all__ = [ "iterators", "polynomials"]
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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