how to draw a meshed geometry?
Show older comments
Hi
I aim to write a code which draws a geometry and then mesh it! Could you please tell me how can I edit this code so it gives out the attached figure? (please ignore the colorful pattern, I only need a meshed geometry)
% Define the vertices of the triangle
v1 = [0, 0];
v2 = [20, 0];
v3 = [30, -10];
v4 = [50, -10];
v5 = [50, -20];
v6 = [0, -20];
% Create a matrix with the vertices as rows
vertices = [v1; v2; v3; v4; v5; v6];
% Define the faces of the triangle as a 1-by-3 matrix
faces = [1, 2, 3, 4, 5, 6];
% Create a patch object with the specified vertices and faces
patch('Vertices', vertices, 'Faces', faces, 'FaceColor', 'white');
% Set the axis limits and labels
axis([0, 50, -20, 0]);
xlabel('x-axis');
ylabel('y-axis');
hold on
x1=0;
x2=50;
y1=0;
y2=-20;
npoints_x=51;
npoints_y=21;
% Create a grid of points using the meshgrid function
x_grid = linspace(x1, x2, npoints_x);
y_grid = linspace(y1, y2, npoints_y);
hold on
[X, Y] = meshgrid(x_grid, y_grid);
hold on
mesh (X,Y,zeros(size(X)))

Accepted Answer
More Answers (0)
Categories
Find more on Polygons 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!