Hi, I want to how can we convert the contour geometry to stl file?
46 views (last 30 days)
Show older comments
ArxIv
on 26 Oct 2024 at 12:14
Commented: Star Strider
on 29 Oct 2024 at 13:49
Hello,
I would like to know how can we convert 2D-geometry I obtained from isocontour of the signed distance function to stl.file.
This is because I want to generate triangular mesh for the inside of the isocontour using "generateMesh" function.
For example, I need to mesh the inside of the circular domain shown in contour.png. The isocontour is plottted using the code below.
Plus, I would be happy if you could inform me how to conduct this meshing without stl.file.
clc; clear; close all;
% Generating simple SDF
[x, y] = meshgrid(linspace(-2, 2, 100), linspace(-2, 2, 100));
sdf = sqrt(x.^2 + y.^2) - 1;
% Extracting 0-level isocontour of the SDF.
isoValue = 0;
contour(x(1,:), y(:,1), sdf, [isoValue isoValue]);
0 Comments
Accepted Answer
Star Strider
on 26 Oct 2024 at 14:27
Try something like this —
% clc; clear; close all;
% Generating simple SDF
[x, y] = meshgrid(linspace(-2, 2, 100), linspace(-2, 2, 100));
sdf = sqrt(x.^2 + y.^2) - 1;
% Extracting 0-level isocontour of the SDF.
isoValue = 0;
c = contour(x(1,:), y(:,1), sdf, [isoValue isoValue]);
axis('equal')
x = c(1,2:end).'; % First Row Of ‘c’ Are The ‘X’ Coordinates, Delete The First Element From Each
y = c(2,2:end).'; % Second Row Of ‘c’ Are The ‘Y’ Coordinates, Delete The First Element From Each
DT = delaunay(x,y); % Delaunay Triangulation
figure
triplot(DT, x, y) % Plot Result
axis('equal','padded')
TR = triangulation(DT,x,y); % Create ‘triangulation’ Object
stlwrite(TR, 'STL_Test.stl', 'text') % Write Triangulation Object To STL File
TRr = stlread('STL_Test.stl') % Check: Read Triangulation Object From STL File
boundaryEdges = freeBoundary(TRr).'; % Get Boundary Edges
figure
triplot(TRr) % Plot ‘triangulation’ Objeect
hold on
plot(TRr.Points(boundaryEdges,1), TRr.Points(boundaryEdges,2), '-r', 'LineWidth',2) % Plot Boundary
hold off
axis('equal','padded')
.
4 Comments
More Answers (0)
See Also
Categories
Find more on Triangulation Representation 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!