Hello it`s my first post here. I want to write matlab script for Delaunay triangulation. Here is my script:
clear all;clc
%% Delaunay
x=[ 160.1671 366.9226 430.7894 540.1208 660.2771 508.7287 252.1787];
y=[ 223.9615 259.5000 120.5769 245.5000 283.1923 472.7308 469.5000];
%
x=x';
y=y';
%orginal plot
dd=delaunay(x,y);
dt=TriRep(dd,x,y);
triplot(dt);
z=[x.^2+y.^2]
i=1:length(x);
ptk=[i' x y]
%% main loop
l=0;
for i=1:length(x)-2
for j=1+i:length(x)
for k=1+i:length(x)
if (j ~= k)
l=l+1;
xn = (y(j)-y(i))*(z(k)-z(i)) - (y(k)-y(i))*(z(j)-z(i));
yn = (x(k)-x(i))*(z(j)-z(i)) - (x(j)-x(i))*(z(k)-z(i));
zn = (x(j)-x(i))*(y(k)-y(i)) - (x(k)-x(i))*(y(j)-y(i));
if (zn < 0)
border=zn;
for m=1:length(x)
border = (border) & ...
((x(m)-x(i))*xn +...
(y(m)-y(i))*yn +...
(z(m)-z(i))*zn <= 0);
if (border)
ii(m)=[i];
jj(m)=[j];
kk(m)=[k];
end
end
end
end
end
end
end
wart=[ii' jj' kk']
dd
figure(2)
triplot(wart,x,y)
This is what I should get from this script. This matrix is generated as delaunay() matlab function:
dd =
6 7 2
7 1 2
4 6 2
1 3 2
4 3 5
6 4 5
2 3 4
This is what I get from implementation :
wart =
4 7 6
4 7 5
4 7 5
4 7 5
4 7 5
4 6 5
4 6 5
Could anyone of you tell me what is wrong with this ? Where is a mistake or simply guide me?
jils.
border=false
would have the same effect. What is intended? – Danielborder=(zn < 0);
is the correct translation of the c-code. – Daniel