Question: I try to write MATLAB code for De Launay triangulation. It is incomplete. Result needs to match Matlab s built - in function. Some of

I try to write MATLAB code for De Launay triangulation. It is incomplete. Result needs to match Matlabs built-in function. Some of my original points are not included in the triangle formation. I need someone to help me fix the actual code. I have looked over it myself for errors & illogical mistakes for over 2 weeks. I posted once, and someone gave general tips for fixing code but it did not help me. Using that, I tried again for another week, but I have the same issue. Please help me fix the code, which I attach in the photo because I am unable to paste or attach files.
In attached image, I include result from MATLABs built-in De Launay function (blue). I am not supposed to use any built-in function except to test, but I found that using inv(A)*b instead of A\b produces slightly better result but still incomplete results so the general issue remains. I have attached all figures from my results using both backslash and inv(A)*b (red) and I know my solution output should be like the other (blue triangulation) image on the bottom, where the sum of all areas is equal to the sum of a polygon. Mine is not even properly enclosed.
I am testing on dataset of 300 points, but I cannot attach data to this post. Instead, I paste data here for first 50 rows, so you can test with the same data by simply pasting this matrix into MATLAB. See the that data, as matrix xy, below.
Please see the attached image for my code and results (red top) vs.the correct result (bottom in blue). Please, help me to get a proper code for the correct results. I have written so you can copy/paste the following and it should run already. I cannot attach files.
clear
xy=[
-3.68,4.06;
8.03,-7.25;
-1.94,4.43;
-4.56,6.81;
-6.58,2.01;
-1.38,-0.18;
-2.05,-2.63;
-1.38,-2.86;
7.31,-2.03;
-2.36,-3.61;
-4.10,8.37;
8.43,-3.52;
7.75,7.41;
6.13,-4.34;
8.13,5.64;
-8.31,6.21;
-4.87,5.78
5.80,5.35;
-2.40,-2.25;
5.07,-3.98;
2.16,5.86;
3.92,5.51;
5.95,2.82;
-4.48,-6.28;
8.66,7.35;
-8.81,-3.09;
0.76,2.89;
-6.28,-7.65;
-1.26,5.41;
-3.44,-0.79;
-1.90,-6.98;
-7.16,6.39;
2.76,4.55;
0.51,5.21;
0.08,-0.21;
5.77,-5.43;
0.20,-0.34;
2.81,-6.14;
-0.65,6.83;
3.08,-8.18;
-5.02,-1.73;
2.55,-6.99;
-0.60,1.22;
5.49,-1.80;
-7.78,-7.73;
8.31,-0.22;
-5.19,-6.27;
7.13,-8.43;
-2.81,1.36;
8.64,1.55];
x = xy(:,1);
y = xy(:,2);
N = length(x);
c = zeros(N*(N-1)*(N-2)/6,2);
r = zeros(N*(N-1)*(N-2)/6,1);
num =0;
T =[];
tol=1e-4;
for i =1:N
for j = i+1:N
for k = j+1:N
if i ~= j && i ~= k && j ~= k
A =[2*x(i),2*y(i),1; 2*x(j),2*y(j),1; 2*x(k),2*y(k),1];
if abs(det(A))0
IP =(x - c1(1)).^2+(y - c1(2)).^2= r1^2; %stores
if any(IP)
continue;
else
num = num +1; %increase incriment
c(num, :) = c1; %store coordinates of current triangle
r(num)= r1;
T(end+1, :) =[i, j, k];
end
end
end
end
end
end
T = T(any(T,2), :);
% Plot the triangulation
figure;
plot(x, y,'o');
hold on;
%make sure to ad traingle x and triangle y to the end to close in the
%%triangle
for i =1:size(T,1)
idx_vert = T(i, :);
triangle_x = x(idx_vert);
triangle_y = y(idx_vert);
plot(triangle_x, triangle_y,'r-', 'LineWidth', 2);
plot(triangle_x, triangle_y,'ro', 'MarkerFaceColor', 'r', 'MarkerSize', 8); % Plot vertices
end
hold off;
xlabel('X');
ylabel('Y');
title('Triangulation');
Please help me fix actual code itself to get correct triangulation that matches result from using Delaunay function built in MATLAB. I need to consider every possible i,j,k combination of points. All points should be included in triangles, but mine does not include all. I did the tolerance to try to see why my matrix is singular. IDK that this is causing it to skip some points though. My results are close, so it should not require many changes.
Algorithm: 1. Start with N points. 2. Select points i,j,k so I not equal j not equal k.3. Draw circle passes through i,j,k 4. Check for points inside circle: If no points: store i,j,k triangle If points, go back to step 2. THANK YOU IN ADVANCE!
I try to write MATLAB code for De Launay

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!