Drawing of Tetrahedron, Pentahedron and sphere and to generate surafec triangular mesh.
11 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
Arun
on 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:
%Tetrahedron
% 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];
%Pentahedron
% 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];
%Sphere
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
figure;
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);
% For visualization
figure;
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:
1. For “triangulation” function -: https://www.mathworks.com/help/matlab/ref/triangulation.html
2. For “trisurf” function -: https://www.mathworks.com/help/matlab/ref/trisurf.html
Hope this helps.
0 Comments
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!