How to remove triangles in a hollow hemisphere shape?

14 vues (au cours des 30 derniers jours)
Darsh
Darsh le 29 Juin 2023
Modifié(e) : Darsh le 30 Juin 2023
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.
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:
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');

Réponse acceptée

Khushi Yadav
Khushi Yadav le 30 Juin 2023
Hi @Darsh,
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:
  1. Find the distances from the origin for each triangle vertex.
  2. Find the indices of triangles with all vertices at the outer circumference by comparing it with the outer radius value.
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:
  1 commentaire
Darsh
Darsh le 30 Juin 2023
Modifié(e) : Darsh le 30 Juin 2023
@Khushi Yadav This works but this also seems to be removing some triangles on the outer hemisphere and bottom part between outer and inner hemisphere. I have attached the pictures to this comment.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Condensed Matter & Materials Physics dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by