- Find the distances from the origin for each triangle vertex.
- Find the indices of triangles with all vertices at the outer circumference by comparing it with the outer radius value.
How to remove triangles in a hollow hemisphere shape?
5 ビュー (過去 30 日間)
古いコメントを表示
So I have this code where I am designing a hollow hemispherical shape and I want to create a 3D volume to input it into FEBio software.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1422648/image.jpeg)
I am using delaunay triangulation for meshing. But the problem is when I rotate to see the bottom, I am seeing is that there are triangles there of this 3D model as shown below:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1422653/image.jpeg)
How do I remove these triangles that are connected at the bottom? I want to triangles only on the surface of the inner and outer hemispheres and between them.
clear
clc
outerRadius = 7.8; % Outer radius of the hemisphere
innerRadius = 7.3; % Inner radius of the hollow region
theta = linspace(0, pi/2, 100);
phi = linspace(0, 2*pi, 100);
[THETA, PHI] = meshgrid(theta, phi);
% Calculate the coordinates for the outer hemisphere
X_outer = outerRadius * cos(PHI) .* sin(THETA);
Y_outer = outerRadius * sin(PHI) .* sin(THETA);
Z_outer = outerRadius * cos(THETA);
% Calculate the coordinates for the inner hemisphere
X_inner = innerRadius * cos(PHI) .* sin(THETA);
Y_inner = innerRadius * sin(PHI) .* sin(THETA);
Z_inner = innerRadius * cos(THETA);
X = [X_outer(:); X_inner(:)];
Y = [Y_outer(:); Y_inner(:)];
Z = [Z_outer(:); Z_inner(:)];
% Combine the coordinates of the outer and inner hemispheres
points = [X, Y, Z];
% Remove duplicate points
[~, uniqueIndices, ~] = unique(points, 'rows', 'stable');
points = points(uniqueIndices, :);
% Separate the updated coordinates
X = points(:, 1);
Y = points(:, 2);
Z = points(:, 3);
% Generate the triangulated mesh
tri = delaunay(X, Y, Z);
% Plot the mesh
figure; set(gcf,'WindowState','maximized');
trimesh(tri, X, Y, Z);
xlabel('X'); ylabel('Y'); zlabel('Z');
title('Triangulated Mesh');
0 件のコメント
採用された回答
Khushi Yadav
2023 年 6 月 30 日
I understand that you are trying to create a 3D hollow hemispherical shape using Delaunay triangulation for meshing and you want to remove the triangles at the bottom of the hemisphere that are visible when the model is rotated, while keeping only the triangles that lie between the inner and outer surfaces.
One of the possible work arounds could be removing all the triangles that have all three vertices on the outer circumference.
The steps are:
Please refer the following code:
clear
clc
% Outer radius of the hemisphere
outerRadius = 7.8;
% Inner radius of the hollow region
innerRadius = 7.3;
theta = linspace(0, pi/2, 100);
phi = linspace(0, 2*pi, 100);
[THETA, PHI] = meshgrid(theta, phi);
% Calculate the coordinates for the outer hemisphere
X_outer = outerRadius * cos(PHI) .* sin(THETA);
Y_outer = outerRadius * sin(PHI) .* sin(THETA);
Z_outer = outerRadius * cos(THETA);
% Calculate the coordinates for the inner hemisphere
X_inner = innerRadius * cos(PHI) .* sin(THETA);
Y_inner = innerRadius * sin(PHI) .* sin(THETA);
Z_inner = innerRadius * cos(THETA);
X = [X_outer(:); X_inner(:)];
Y = [Y_outer(:); Y_inner(:)];
Z = [Z_outer(:); Z_inner(:)];
% Combine the coordinates of the outer and inner hemispheres
points = [X, Y, Z];
% Remove duplicate points
[~, uniqueIndices, ~] = unique(points, 'rows', 'stable');
points = points(uniqueIndices, :);
% Separate the updated coordinates
X = points(:, 1);
Y = points(:, 2);
Z = points(:, 3);
% Generate the triangulated mesh
tri = delaunay(X, Y, Z);
% Calculate the distances from the origin for each triangle vertex
distances = sqrt(X(tri).^2 + Y(tri).^2 + Z(tri).^2);
% Find the indices of triangles with all vertices at the outer circumference
%ensures that all three vertices of the triangle are very close to the outer radius
circumferenceIndices = find(abs(distances - outerRadius) < 1e-6);
% Filter out triangles with all vertices at the outer circumference
trianglesToRemove = ~ismember(1:size(tri, 1), circumferenceIndices);
tri(trianglesToRemove, :) = [];
% Plot the mesh
figure; set(gcf,'WindowState','maximized');
trimesh(tri, X, Y, Z);
xlabel('X'); ylabel('Y'); zlabel('Z');
title('Triangulated Mesh');
For more understanding, kindly go through the following documentation:
その他の回答 (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!