Create meshes on patch objects

조회 수: 3 (최근 30일)
Gozde Basara
Gozde Basara 2015년 8월 3일
답변: Gautam 2025년 2월 10일
Is it possible to create meshes on patch objects? Or divide a patch object in smaller pieces?

답변 (1개)

Gautam
Gautam 2025년 2월 10일
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

카테고리

Help CenterFile Exchange에서 Polygons에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by