Meshing a 2D contour plot
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Elliot Bontoft
am 14 Mai 2020
Beantwortet: Jiexian Ma
am 6 Apr. 2025
I am looking to create a mesh within the lines of a 2D contour plot.
For example, with the code:
f = peaks;
contour(f,[2 2])
You achieve the following plot:

I would like to be able to generate a mesh inside and outside of the contour lines (within a domain of say 50x50 for this example).
Could someone suggest the best way to achieve this?
Thank you in advance.
2 Kommentare
Ameer Hamza
am 14 Mai 2020
Are you trying to create a mesh plot? If you want to plot both inside and outside the contour lines, isn't it the same as a regular mesh plot? Can you show an example image of what is your intended output?
Akzeptierte Antwort
darova
am 14 Mai 2020
Use initmesh
clc,clear
x1 = [0 5 5 0]; % rectangle
y1 = [0 0 3 3];
[x2,y2] = pol2cart(0:.3:2*pi,1); % circle
gd2 = [2;length(x2);x2(:)+1.5;y2(:)+1.5]; % circle geometry
gd1 = gd2*0;
gd11 = [2;length(x1);x1(:);y1(:)]; % rectangle geometry
gd1(1:length(gd11)) = gd11;
dl = decsg([gd1 gd2],'P1-P2',char('P1','P2')'); % decomposition geometry
[p,e,t] = initmesh(dl); % build a mesh
pdemesh(p,e,t) % display mesh
dl2 = decsg(gd2); % decomposition of circle
[p,e,t] = initmesh(dl2); % build a mesh
hold on
pdemesh(p,e,t) % display emsh
hold off

4 Kommentare
Weitere Antworten (1)
Jiexian Ma
am 6 Apr. 2025
As far as I know, there are two ways to do this.
- Method 1. Create geometry through Constructive Solid Geometry and obtain mesh via PDE toolbox. darova's answer used this method.
- Method 2. Create geometry via polyshape and generate mesh via Im2mesh package.
Personally, I perfer method 2 because you can edit polyshape object easily.








You could check demo14 to demo17 in Im2mesh package. I provide a few examples.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Geometry and Mesh finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!