Create meshes on patch objects
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Is it possible to create meshes on patch objects? Or divide a patch object in smaller pieces?
0 commentaires
Réponses (1)
Gautam
le 10 Fév 2025
Hello @Gozde Basara
MATLAB doesn't have a built-in function to divide a patch object in smaller pieces, but you can implement a custom function to subdivide the faces of a patch object. This typically involves splitting each face into smaller faces.
Here's a sample code you can refer to
% Define a simple triangular patch
vertices = [0 0 0; 1 0 0; 0 1 0];
faces = [1 2 3];
% Create the patch object
figure;
p = patch('Vertices', vertices, 'Faces', faces, 'FaceColor', 'cyan');
% Subdivide the patch
[newVertices, newFaces] = subdivide(vertices, faces);
% Visualize the refined mesh
hold on;
patch('Vertices', newVertices, 'Faces', newFaces, 'FaceColor', 'none', 'EdgeColor', 'black');
axis equal;
% Function to subdivide each triangle into smaller triangles
function [newVertices, newFaces] = subdivide(vertices, faces)
newVertices = vertices;
newFaces = [];
for i = 1:size(faces, 1)
% Get the vertices of the current face
v1 = vertices(faces(i, 1), :);
v2 = vertices(faces(i, 2), :);
v3 = vertices(faces(i, 3), :);
% Calculate midpoints
m12 = (v1 + v2) / 2;
m23 = (v2 + v3) / 2;
m31 = (v3 + v1) / 2;
% Add new vertices
newVertices = [newVertices; m12; m23; m31];
idx = size(newVertices, 1) - 2:size(newVertices, 1);
% Create new faces
newFaces = [newFaces;
faces(i, 1), idx(1), idx(3);
idx(1), faces(i, 2), idx(2);
idx(3), idx(2), faces(i, 3);
idx(1), idx(2), idx(3)];
end
end
0 commentaires
Voir également
Catégories
En savoir plus sur Polygons dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!