how to create a mesh within the geometry?

35 ビュー (過去 30 日間)
Pooneh Shah Malekpoor
Pooneh Shah Malekpoor 2023 年 3 月 24 日
回答済み: Adam Danz 2023 年 3 月 25 日
Hi
There is a geometry like :
How to plot the meshed geometry like this ?lets say the mesh dimension is 1*1
  2 件のコメント
Joe Vinciguerra
Joe Vinciguerra 2023 年 3 月 24 日
What have you tried so far?
Do you just need to display the shape with gridlines, or is there underlying data that needs to be mapped or otherwise associated to the grid?
Pooneh Shah Malekpoor
Pooneh Shah Malekpoor 2023 年 3 月 24 日
I have used Plot command but it is not generating regular meshed geometry! I just need the shape with gridlines for this 45 deg sloped geometry

サインインしてコメントする。

回答 (1 件)

Adam Danz
Adam Danz 2023 年 3 月 25 日
This solution creates a grid based on the coordinates stored in xy. It then removes any grid coordinates outside of the polygon defined by xy by replacing those values with NaN. The grid is plotted using surf() and the polygon perimeter is plotting using polyshape/plot.
% nx2 [x,y] values that define the polygon
xy = [0 0; 20 0; 25 -5; 45 -5; 45 -10; 0 -10];
% Compute the grid covering the entire extent of the polygon
interval = 1;
xGridVals = min(xy(:,1)) : interval : max(xy(:,1));
yGridVals = min(xy(:,2)) : interval : max(xy(:,2));
[xg,yg] = meshgrid(xGridVals ,yGridVals);
% Remove grid values outside of the polygon
[in,on] = inpolygon(xg,yg,xy(:,1),xy(:,2));
xg(~(in|on)) = NaN;
yg(~(in|on)) = NaN;
% Plot the grid & Polygon
surf(xg,yg,zeros(size(xg)),'FaceColor','none')
hold on
plot(polyshape(xy(:,1),xy(:,2)),'FaceColor','none')
axis equal
view(2)
grid off

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by