#7744: STL Export -- Allows for 3d printing of surfaces
---------------------------+------------------------------------------------
   Reporter:  colah        |       Owner:  colah          
       Type:  enhancement  |      Status:  new            
   Priority:  major        |   Milestone:  sage-4.3.1     
  Component:  graphics     |    Keywords:  3D-Printing STL
Work_issues:               |      Author:  colah          
   Upstream:  N/A          |    Reviewer:                 
     Merged:               |  
---------------------------+------------------------------------------------
 {{{
 def surface_to_stl(surface):
     """
     Return an STL representation of the surface.

     INPUT:
         - `surface` -- any surface, eg. output of a 3d plot function.

     OUTPUT:
         A string that represents the surface in the STL format.

     COMMENTS:
         (1) You must view the surface before plotting it.
             Otherwise, this will not work.
         (2) In order to do 3d printing with this, you will need to
             convert it into gcode. Skeinforge is an open-source
             program that can do this.
         (3) The size of the surface is not normalized in export.
             Sage's units will become the units of the STL
             description. These seem to be ~0.05 cm (at least when
             printed using skeinforge -> replicatorg -> hacklab.to's
             cupcake).
         (4) Be aware of the overhang limits of your 3d printer;
             most printers can only handle an overhang of Pi/2 (45*)
             before your model will start drooping.

     EXAMPLES:
         sage: x,y,z = var('x,y,z')
         sage: a = implicit_plot3d(x^2+y^2+z^2-9, [x,-5,5],
 [y,-5,5],[z,-5,5])
         sage: a
         sage: f=file.open("foo.stl",'w')
         sage: f.write(surface_to_stl(a))
         sage: f.close()
     """

     out =  "solid mathsurface\n"
     for i in surface.face_list():
         n = ( i[1][1]*i[2][2] - i[2][1]*i[1][2],
               i[1][2]*i[2][0] - i[1][0]*i[2] 2],
               i[1][0]*i[2][1] - i[2][0]*i[1][1] )
         abs = (n[0]^2+n[1]^2+n[2]^2)^0.5
         n= (n[0]/abs,n[1]/abs,n[2]/abs)
         out += "  facet normal " + repr(n[0])  + " " + repr(n[1])    + " "
 + repr(n[2])
         out += "    outer loop\n"
         out += "      vertex " + repr(i[0][0]) + " " + repr(i[0][1]) + " "
 + repr(i[0][2]) + "\n"
         out += "      vertex " + repr(i[1][0]) + " " + repr(i[1][1]) + " "
 + repr(i[1][2]) + "\n"
         out += "      vertex " + repr(i[2][0]) + " " + repr(i[2][1]) + " "
 + repr(i[2][2]) + "\n"
         out += "    endloop\n"
         out += "  endfacet\n"
     out += "endsolid surface\n"
     return out
 }}}

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/7744>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

--

You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.


Reply via email to