user3260487
user3260487

Reputation: 75

Finding area of Resultant triangles of Delaunay trianglulation

After applying delaunay triangulation is it possible to find the area of each triangles formed? Is there any function in matlab to do it? Kindly clarify me. Advance thanks

Upvotes: 2

Views: 2399

Answers (4)

Yoav Zack
Yoav Zack

Reputation: 205

The answers here were close to true in my case, but not quite, so I add my voice to the discussion for future people who may need it.

When trying the solutions given here I got the following error:

Error using reshape
Number of elements must not change. Use [] as one of the size inputs to
automatically calculate the appropriate size for that dimension.

Error in polyarea (line 46)
  area = reshape(abs(sum( (x([2:siz(1) 1],:) - x(:,:)).* ...

The problem was that x(tri') gave a vector, and not a matrix. Instead, I did the following:

pt = tri.Points;
conn = tri.ConnectivityList;
xmat = reshape(pt(conn,1), [], 2);
ymat = reshape(pt(conn,2), [], 2);
Avec = polyarea(xmat, ymat, 2);

And this solved my problem, while still being a vectorized operation.

Upvotes: 0

Joe Ercolino
Joe Ercolino

Reputation: 83

This solution works, but is not vectorized.

DT = delaunayTriangulation(X,Y);

NTriangles = size(DT.ConnectivityList,1);

% Triangles' Area Calculation (Try to vectorize)
Areas = zeros(NTriangles,1);
for i = 1:NTriangles
    PointIndexes = DT.ConnectivityList(i,:);
    Areas(i) = polyarea(DT.Points(PointIndexes,1),DT.Points(PointIndexes,2));
end

Upvotes: 0

Vishu
Vishu

Reputation: 146

I was facing the same doubt but thankfully, I was able to crack it, try this:

tri = delaunay(x,y);
areas = polyarea(x(tri'),y(tri'),2);

This will give you areas of each triangle formed.

Do let me know if you find any difficulties.

P.S: the tri' means the transpose of the matrix.

Upvotes: 2

nkjt
nkjt

Reputation: 7817

This can be done with polyarea - note the use of the dim option.

tri = delaunay(x,y);
areas = polyarea(tri(x),tri(y),2);

Upvotes: 0

Related Questions