![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1509924/image.png)
How can I add a face to a 3D geometry without defining edges in advance?
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
By using code like the following, a cuboid can be created as a 3D geometry:
gm = multicuboid(1,1,1);
This cuboid can be used as geometry for a PDE model. In order to obtain the discretized output matrix for an output which contains a part of one face of the cuboid using the function linearizeOutput of the PDE toolbox, I want to define an additional face on a part of one face of the cuboid. This could theoretically be done by using the function addVertex, but addVertex can't be used here because it needs edges that have been defined in advance. But I could not find a MATLAB function that can be used to define edges arbitrarily, but only for defining vertices. So does anyone have an idea how I can add the face without defining edges in advance or how I can define edges from vertices?
Thanks!
0 comentarios
Respuestas (1)
Avni Agrawal
el 13 de Oct. de 2023
Hi,
I understand that you are trying to add a face to a 3D geometry without defining edges in advance in MATLAB. To achieve this, you can use the `patch` function. The `patch` function allows you to create a surface by specifying the vertices and faces of the geometry.
Here's an example that demonstrates how to add a face to a 3D geometry in MATLAB:
% Define the vertices of the geometry
vertices = [0, 0, 0; 1, 0, 0; 1, 1, 0; 0, 1, 0; 0, 0, 1; 1, 0, 1; 1, 1, 1; 0, 1, 1];
% Define the faces of the geometry
faces = [1, 2, 3, 4; 5, 6, 7, 8; 1, 2, 6, 5; 2, 3, 7, 6; 3, 4, 8, 7; 4, 1, 5, 8];
% Plot the initial geometry
figure;
patch('Vertices', vertices, 'Faces', faces, 'FaceColor', 'blue', 'EdgeColor', 'black');
axis equal;
grid on;
% Add a new face to the geometry
newFace = [2, 6, 7, 3]; % Define the new face vertices
hold on;
patch('Vertices', vertices, 'Faces', newFace, 'FaceColor', 'red', 'EdgeColor', 'black');
hold off;
In this example, we first define the vertices and faces of the initial geometry. Then, we plot the initial geometry using the `patch` function. Finally, we add a new face to the geometry by specifying the vertices of the new face and plotting it using the `patch` function again.
The resulting figure will show the initial geometry (a cube) in blue and the added face (a triangular face on one side of the cube) in red.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1509924/image.png)
Please refer to the below documentation for further assistance: https://in.mathworks.com/help/matlab/ref/patch.html
I Hope this helps.
0 comentarios
Ver también
Categorías
Más información sobre Geometry and Mesh en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!