Azzera filtri
Azzera filtri

Drawing of Tetrahedron, Pentahedron and sphere and to generate surafec triangular mesh.

13 visualizzazioni (ultimi 30 giorni)
I have to validate my matlab model with some ideal shape geometry. For this I want to draw geometry such as tetrahdeon, pentahedron and so on and sphere. and then want to crate surface mesh(triangulation) for getting surface points which further i will fee into my matlab model.

Risposte (1)

Arun il 17 Apr 2024
Hi Saurav,
I understand that you want to create some ideal geometry shapes, such as a tetrahedron, pentahedron and sphere. The goal is to create a surface mesh for these shapes and then get surface points to feed them to a MATLAB model.
To obtain the required surface points, we need to:
1. Define the shape: Specify the geometric parameters that describe your shape of interest.
2. Use triangulation to get the points: Apply “triangulation” method on the shape with faces and vertices as input.
Here is a sample code that could be useful:
Step-1 :Define the required geometry shapes:
% Define vertices
V_tetra = [1, 1, 1; -1, -1, 1; -1, 1, -1; 1, -1, -1];
% Define faces
F_tetra = [1, 2, 3; 1, 2, 4; 2, 3, 4; 1, 3, 4];
% Define vertices
V_penta = [0, 0, 0; 1, 0, 0; 0.5, sqrt(3)/2, 0; 0.5, sqrt(3)/6, sqrt(6)/3; -0.5, sqrt(3)/6, sqrt(6)/3];
% Define faces (assuming a pyramid with a pentagonal base)
F_penta = [1, 2, 3; 1, 3, 4; 2, 3, 5; 1, 2, 5; 3, 4, 5];
n = 20; % Density of points
r = 1; % Radius
% Create mesh for theta and phi
[phi, theta] = meshgrid(linspace(0, 2*pi, n), linspace(0, pi, n));
% Convert spherical to Cartesian coordinates
X = r * sin(theta) .* cos(phi);
Y = r * sin(theta) .* sin(phi);
Z = r * cos(theta);
V_sphere = [X(:), Y(:), Z(:)];
F_sphere = convhull(X(:),Y(:), Z(:));
Step-2 : Apply “triangulation” function to shapes to get the required surface points:
% For a tetrahedron (replace V and F with tetratahedron's vertices and faces)
T_tetra = triangulation(F_tetra, V_tetra);
% For visualization
trisurf(T_tetra, 'FaceColor', 'cyan');
% For a pentahedron (replace V and F with pentahedron's vertices and faces)
T_penta = triangulation(F_penta, V_penta);
% For visualization
trisurf(T_penta, 'FaceColor', 'magenta');
% For a sphere (replace V and F with sphere's vertices and faces)
T_sphere = triangulation(F_sphere, V_sphere);
Warning: Some input points are not referenced by the triangulation.
% For visualization
trisurf(T_sphere, 'FaceColor', 'yellow')
The values “T_tetra”, “T_penta”, and “T_sphere” represent trangulation structure with fields “Points” and “ConnectivityList”. These structures can be utilized further to feed data into a MATLAB model.
Please refer the shared documentation links for more information:
Hope this helps.

Community Treasure Hunt

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

Start Hunting!

Translated by