Hi, I want to how can we convert the contour geometry to stl file?
조회 수: 47 (최근 30일)
이전 댓글 표시
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
채택된 답변
Star Strider
2024년 10월 26일 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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Triangulation Representation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!