MATLAB: How to create 2-D geometry from a sequence of points in PDE toolbox

2dgeometryPartial Differential Equation Toolboxpdepolygon

I have a set of (x, y) points in 2D. I want to solve a PDE on the boundary defined by these points. How to create 2-D geometry from this sequence of points in PDE toolbox?

Best Answer

Following is one approach to create 2-D geometry from a sequence of points. This will create a closed polygon. This approach can only be used in MATLAB 2018a. This is because prior to 2018a, the function "geometryFromMesh" only accepts 3D points and makes 3D models. In 2018a, this function can also support 2D points creating 2D models.
X = [0 0; 4 0; 8 0; 12 0; 16 0; 16 2; 2 2; 2 3; 8 3; 8 5; 0 5];
pg = polyshape(X(:,1),X(:,2));
plot(pg);
tr = triangulation(pg);
% Create a PEDE Model
pdem = createpde;
% Create the geometry from the triangulatiom
% Some of the intermediate points in the polygon are abstracted away
pdem.geometryFromMesh(tr.Points', tr.ConnectivityList')
pdegplot(pdem,'VertexLabels','on')
In the following link there is another generalized example for creating circle, rectangle, ellipse shaped geometries in the PDE toolbox:
This approach can be followed in releases prior to 2018a as well (verified in 17b).