File Exchange Pick of the Week

June 5th, 2009

Writing to STL files

Jiro's pick this week is surf2stl by Bill McDonald.

About a month ago, at a seminar I gave at a university, a graduate student came up to me and asked whether there was a function for writing out 3D model files. Specifically, he was referring to STL files (stereolithography files). It was a topical question because it came soon after I talked about some of the exporting capabilities in MATLAB for graphical file formats.

I knew that we didn't have any built in, but I promptly suggested checking out the File Exchange. I've seen a few functions for reading from STL files, so I figured there would be counterparts. Sure enough, there were a few. Here's a list of entries with a tag of "stl".

From the list, I am highlighting Bill's surf2stl. It has nice help, clean code, good reviews, and has even inspired another entry.

Download and give it a try!

Comments?


Get the MATLAB code

Published with MATLAB® 7.8

17 Responses to “Writing to STL files”

  1. Yousif m. ali replied on :

    I have the following question and hope that you may shed some light on it. Thanks in advance
    I am working on image, how to recover scale, rotation, shear from projective t-matrix?
    For example:
    1.6971 1.838 0
    -1.314 0.989 0
    0 0 1

  2. jiro replied on :

    Yousif, I’m not sure I understand your question. It’s probably better to post your question on the newsgroup

    http://www.mathworks.com/matlabcentral/newsreader/

  3. Ro replied on :

    How,
    I have download the code,
    but I really don’t know what is x,y,z mean in the file.
    My question is, I have a 3D matrix, and how can I use surf2stl() to export a STL file?
    Thanks for answering!

  4. jiro replied on :

    Ro,

    X, Y, Z corresponds to the inputs used by SURF. 3D matrix would not work with SURF, only 2D matrices.

  5. Ro replied on :

    Thanks for answering,
    So, do you know anu way to convert 3D matrix to STL file?

  6. jiro replied on :

    Ro,
    I can’t really answer that because I don’t know what your 3D matrix represents. First step is to get your matrix in a form that can be visualized using the command SURF. For that, I suggest reading the documentation for SURF. Once that’s done, then you can use surf2stl function highlighted in this blog.

  7. Ro replied on :

    jiro,
    My 3D matrix represents many points. I have tried the command Surf. But it only works with the 2D matrix. For example, the 3D matrix represents many points in (x,y,z) format. The command Surf can work the same ‘z’ coordinate, so I can’t figure out how to transfer to 3D STL.

  8. jiro replied on :

    Ro,
    I’m sorry but I don’t know how to solve your problem. In order to use surf2stl, you have to represent your data in x,y,z format — the same way it is used in surf(x,y,z). Since your 3D matrix does not work with surf, you have to first convert it to something that does.

    One question, what is the SIZE of your 3D matrix. Is it something like m-by-n-by-o ?

    I suggest either posting your question in the newsgroup or contacting support.

  9. Ro replied on :

    jiro,
    I think I can figure out something.
    So the question now is: Asuming I have three points, there coordinates are (x1,y1,z1),(x2,y2,z2)and(x3,y3,z3).
    How can I use the command surf2stl() to export a stl file?
    Thanks for answering me again!

  10. Ro replied on :

    jiro,
    I have solved the problem by the command patch2stl.
    Thanks for your suggestion!

  11. jiro replied on :

    Ro,
    I’m glad it worked. It seems like your data was structured more for PATCH, not SURF.

  12. Madeleine replied on :

    Hey jiro,
    did you write the patch2stl code yourself?
    I can’t find anything like that in the other blogs.
    You would really help me if you could publish your patch2stl code.
    Cheers
    Madeleine

  13. jiro replied on :

    @Madeleine,

    “patch2stl” is written by someone else and is available on File Exchange:

    http://www.mathworks.com/matlabcentral/fileexchange/20922-patch2stl

  14. Jo Byung Doo replied on :

    Hey jiro,
    did you write the patch2stl code yourself?
    You would really help me if you could publish your patch2stl code.
    :)

  15. Jo Byung Doo replied on :

    hey, hello
    could you help me, plese?

    i want to know your STL Maltal code
    because, I’m studying on making coronal image by using 3d image :P

  16. jiro replied on :

    @Jo Byung Doo

    See my response #13. I’ve included the link to the File Exchange entry.

  17. Ali replied on :

    Dear, could you help me reading stl file in matlab?
    thanx alot
    Iam drawing a part by AutoCAD and I need to read the part stl file using matlab code, so if you have like that code, please send it to me, and thanx for your help


MathWorks

Brett & Jiro share their favorite user-contributed submissions from the File Exchange.

These postings are the author's and don't necessarily represent the opinions of MathWorks.