4 years ago, when I was study in abroad, I found an interesting problem for solving SPECFEM wave-fields simulation in the preprocessing procedure of building mesh with som vertex points and som boundaries.
The open source code,Triangle, can just generate mesh by using a boudary polygon or some vertexes. But, this thing often occurs and can be described in detail. Some vertexes are existing on the polygon and others are in the boundary polygon. It is hard to process, because mesh can only build from either boundary or vertexes not on the boudary. When mesh is generated from the vertexes, the boundary often can be ignored.
So using Matlab code to generate a mesh by Delaunay method, the code is as follows:
>> x=[1 2 3;4 5 6]
x =
1 2 3
4 5 6
>> y=[4 8 3;6 9 2]
y =
4 8 3
6 9 2
>> delaunayTriangulation(x(:),y(:))
ans =
delaunayTriangulation with properties:
Points: [6×2 double]
ConnectivityList: [5×3 double]
Constraints: []
>> triplot(ans)
Fig1. Matlab mesh generated from vertexes
When there is a boundary that not the same as the Fig1's free boundary. Then incenter function and polygon vertexes should be used to figure out which element should be deleted from the whole elements seen in Fig1.
>> freeBoundary(ans)
ans =
1 5
5 6
6 4
4 3
3 1
Fig2. free boudary
dt=delaunayTriangulation(x(:),y(:))
IC=incenter(dt)
inpolygon(IC(:,1),IC(:,2),x([1,2,5,1]),y([1,2,5,1]))
ans =
5×1 logical array
1
0
0
0
0
The first element is not in the polygon, the true region not contains it.
>> dt.ConnectivityList(1,:)
ans =
1 5 2
>> dt.ConnectivityList(1,1)=[]
Error using delaunayTriangulation/subsasgn
Cannot assign values to the triangulation.
wei.nodes=dt.Points;
wei.connect=dt.ConnectivityList
wei.connect(1,:)=[];
dts=triangulation(wei.connect,wei.nodes);
triplot(dts);
Fig3. The wanted mesh
freeBoundary(ans)
ans =
1 2
2 5
5 6
6 4
4 3
3 1
>> dts=triangulation(wei.connect,dts.Points)
dts =
triangulation with properties:
Points: [6×2 double]
ConnectivityList: [4×3 double]
>> triplot(dts)
>> hold on
>> plot(x(ans),y(ans),'r')
Fig4 The real wanted mesh and boundary
I browse some forums,especially the stack over flow, it says as follows:
The triangulation object is read-only, so you will have to make copies of all the fields. If, as you mentioned, you would like to make a structure with similar fields, you can do as follows:
dts = struct('Points', dt.Points, 'ConnectivityList', dt.ConnectivityList);
Now you can edit the fields.
dts.ConnectivityList(760) = [];
You may be able to plot the new structure, but the methods of the delaunayTriangulation
class will not be available to you.
To plot the result, use trisurf
:
trisurf(dts.ConnectivityList, dts.Points);
4
I was facing same problem. I found another solution. Instead of creating a new struct just create an object of its super class i.e. triangulation class with edited connectivity list. Here is my code
P- list of points
C- Constraints (optional)
dt=delaunayTriangulation(P,C); %created triangulation but dt won't let you change connectivity listlist=dt.ConnectivityList;
%your changes herex=triangulation(list,dt.Points);
Now you can use x
as triangulation object
triplot(x)
how to delete an element can reference the following paper:
[1] https://www.mathworks.com/help/matlab/math/creating-and-editing-delaunay-triangulations.html