how do I convert my patch function into a surface function
11 views (last 30 days)
Show older comments
I have this shape as a patch function, but in order for it to work with the rest of my project it has to be in the surf form. Is there any way to convert it?
figure(1)
v = [0 -15 60; 0 -15 57; 75 -10 60; 75 -10 57; 78 5 60; 78 5 57; 0 0 60 ; 0 0 57; -78 5 60; -78 5 57; -75 -10 60; -75 -10 57];
f = [1 2 4 3; 3 4 6 5; 5 6 8 7; 7 8 10 9; 9 10 12 11; 11 12 2 1;7 1 3 5; 9 11 1 7; 2 4 6 8; 2 8 10 12];
wing = patch('Faces',f,'Vertices',v,'FaceAlpha',1,'FaceColor','green');
0 Comments
Answers (1)
DGM
on 5 Jul 2025
Edited: DGM
on 7 Oct 2025 at 13:56
This is the same question:
To be more specific, #396777 is the exact same mesh, and was asked at the same time by a different user, and the stated goal was to convert the mesh to a surf plot in order to use surf2stl().
If that indeed was the motivation, then don't. There's no point in taking F,V data, gridding it, and then retriangulating it. Just put the FV data that you already have into an STL.
I'll note that we don't have a triangulated mesh. We have a quad mesh, and two of the faces are backwards. Fix that, and just write the mesh to STL.
% the quad mesh
V = [0 -15 60; 0 -15 57; 75 -10 60; 75 -10 57; 78 5 60; 78 5 57; 0 0 60 ; 0 0 57; -78 5 60; -78 5 57; -75 -10 60; -75 -10 57];
F = [1 2 4 3; 3 4 6 5; 5 6 8 7; 7 8 10 9; 9 10 12 11; 11 12 2 1;7 1 3 5; 9 11 1 7; 2 4 6 8; 2 8 10 12];
% the winding is backwards on these two faces
F(end-1:end,:) = fliplr(F(end-1:end,:));
% diagonal subdivision to triangles
F = [F(:,[1 2 3]); F(:,[3 4 1])];
% write it to an STL
% at the time of the question, these were the best options:
%stlwrite_holcombe('blah.stl',F,V) % FEX #20922 or FEX #51200
% if you live in the present and are running a pre-R2018b version:
%stlwrite_legacy('blah.stl',F,V) % FEX #182013
% if you're running a modern version in the present:
stlwrite(triangulation(F,V),'test.stl')
% view the triangulated mesh
patch('faces',F,'vertices',V,'facecolor',[1 1 1]*0.8,'edgecolor','k');
view(3); view(-30,47); axis equal; grid on
Prior to R2018b, you would have used FEX #20922 or #51200. If you are still running one of those old versions today, they're both superceded by FEX #182013.
0 Comments
See Also
Categories
Find more on Polygons in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!