简体   繁体   中英

how to convert delaunay triangulation to .stl (stereolithography) format?

I have found several tools which convert isosurface - class or meshgrid data in MATLAB to an STL format. Examples include stlwrite and surf2stl . What I can't quite figure out is how to take a delaunayTriangulation object and either uses it to create an STL file or convert it into an isosurface object.
The root problem is that I'm starting with an N-by-2 array of boundary points for irregular polygons, so I don't have any simple way to generate an xyz meshgrid. If there's a way to convert the boundary list into an isosurface of the interior region (constant Z-height is all I need), that would also solve my problem.
Otherwise, I need some way to convert the delaunayTriangulation object into something the referenced MATLAB FEX tools can handle.

edit to respond to Ander B's suggestion:

I verified that my triangulated set inside MATLAB is a 2-D sector of a circle. But when I feed the data to stlwrite , and import into Cura , I get a disaster - triangles at right angles or rotate pi from desired, or worse. Whether this is the fault of stlwrite , Cura being sensitive to some unexpected value, or both I can't tell. HEre's what started out as a disc: 在此处输入图片说明 As an example, here's a set of points which define a sector of a circle. I can successfully create a delaunayTriangulation object from these data.

>> [fcx1',fcy1']
ans =
  100.4563   26.9172
   99.9712   28.6663
   99.4557   30.4067
   98.9099   32.1378
   98.3339   33.8591
   97.7280   35.5701
   97.0924   37.2703
   96.4271   38.9591
   95.7325   40.6360
   95.0087   42.3006
   94.2560   43.9523
   93.4746   45.5906
   92.6647   47.2150
   91.8265   48.8250
   90.9604   50.4202
   90.0666   52.0000
   89.1454   53.5640
   88.1970   55.1116
   87.2217   56.6425
   86.2199   58.1561
   85.1918   59.6519
   84.1378   61.1297
   83.0581   62.5888
   81.9531   64.0288
   80.8232   65.4493
   79.6686   66.8499
   78.4898   68.2301
   77.2871   69.5896
   76.0608   70.9278
   74.8113   72.2445
   73.5391   73.5391
   72.2445   74.8113
   70.9278   76.0608
   69.5896   77.2871
   68.2301   78.4898
   66.8499   79.6686
   65.4493   80.8232
   64.0288   81.9531
   62.5888   83.0581
   61.1297   84.1378
   59.6519   85.1918
   58.1561   86.2199
   56.6425   87.2217
   55.1116   88.1970
   53.5640   89.1454
   52.0000   90.0666
   50.4202   90.9604
   48.8250   91.8265
   47.2150   92.6647
   45.5906   93.4746
   43.9523   94.2560
   42.3006   95.0087
   40.6360   95.7325
   38.9591   96.4271
   37.2703   97.0924
   35.5701   97.7280
   33.8591   98.3339
   32.1378   98.9099
   30.4067   99.4557
   28.6663   99.9712
   26.9172  100.4563
   25.1599  100.9108
   23.3949  101.3345
   21.6228  101.7274
   19.8441  102.0892
   18.0594  102.4200
   16.2692  102.7196
   14.4740  102.9879
   12.6744  103.2248
   10.8710  103.4303
    9.0642  103.6042
    7.2547  103.7467
    5.4429  103.8575
    3.6295  103.9366
    1.8151  103.9842
         0  104.0000
   -1.8151  103.9842
   -3.6295  103.9366
   -5.4429  103.8575
   -7.2547  103.7467
   -9.0642  103.6042
  -10.8710  103.4303
  -12.6744  103.2248
  -14.4740  102.9879
  -16.2692  102.7196
  -18.0594  102.4200
  -19.8441  102.0892
  -21.6228  101.7274
  -23.3949  101.3345
  -25.1599  100.9108
  -26.9172  100.4563
         0         0

Building on Ander B's answer, here is the complete sequence. These steps ensure that even concave polygons are properly handled.

Start with two vectors containing all the x and the y coordinates. Then:

% build the constraint list
constr=[ (1:(numel(x)-1))' (2:numel(x))' ; numel(x) 1;];
foodel = delaunayTriangulation(x',y',constr);
% get logical indices of interior triangles
inout = isInterior(foodel);

% if desired, plot the triangles  and the original points to verify.
%  triplot(foodel.ConnectivityList(inout, :),...
    foodel.Points(:,1),foodel.Points(:,2), 'r')
% hold on
%  plot(fooa.Points(:,1),fooa.Points(:,2),'g')

% now solidify
%  need to create dummy 3rd column of points for a solid
point3 = [foodel.Points,ones(numel(foodel.Points(:,1)),1)];
% pick any negative 'elevation' to make the area into a solid
[solface,solvert] = surf2solid(foodel.ConnectivityList(inout,:),...
    point3, 'Elevation', -10);  

stlwrite('myfigure.stl',solface,solvert);

I've successfully turned some 'ugly' concave polygons into STLs that Cura is happy to turn into gCode.

STL is just a format to store in memory mesh information, thus you have the data if you have a mesh, you just need to write it to memory using the right format.

It appears that you input the vertices and faces to the stlwrite function as

stlwrite(FILE, FACES, VERTICES);

And the delaunayTriangulation output gives you a object that has easy access to this data as for an object DT , DT.Points is the vertices, and DT.ConnectivityList is the faces.

You can read more about it in the documentation you linked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM