Ole
Ole

Reputation: 31

Matlab 2.5D Delaunay triangulation vertex normals

I am trying to do what I believe is called 2.5D Delaunay Triangulation and calculation of vertex normals in Matlab. Using the delaunayTriangulation class and related functions, I can triangulate the x,y plane and get the desired mesh. However, trying to extract surface normals only yields normals for a flat surface. This makes perfect sense since I only supplied 2D data to the delaunayTriangulation, but I don't see how the vertexNormal() function is useful in that case. What am I missing - how can I extract normals for the triangulated mesh with the height properties?

I understand how to do this for a grid using surform() or similar functions, but I want this to work for scattered points as well without having to grid them.

Working example to illustrate:

% Generate some data
rng(42); % Seed random gen
[X,Y] = meshgrid( 1:100, 1:100 );
k = ones(15)./(15^2);
Z = conv2(rand(size(X)), k, 'same'); % Smooth data to have a nice surface to test with
% Triangulate
DT = delaunayTriangulation(X(:),Y(:));
% DT.vertexNormal are all [0 0 1] (flat surface...) - makes sense.
DT3 = delaunayTriangulation(X(:),Y(:),Z(:));
% DT3.vertexNormal() --> gives error because we now did 3D delaunayTrinagulation and have tetraheders, not triangles. Also makes sense. 
% DT.Points = [DT.Points, Z(:)]; --> Something crazy like trying to add Z points after triangulation gives error, obviously

Upvotes: 2

Views: 247

Answers (1)

Ole
Ole

Reputation: 31

I figured it out, but will post the answer here for others in need. This is apparently what the triangulation() function is for:

% Triangulate 2D
DT = delaunayTriangulation(X(:),Y(:));
% Triangulate 3D ("2.5D")
DT_3D = triangulation( DT.ConnectivityList, X(:), Y(:), Z(:) );
% Calculate vertex normals
vertex_normals = DT_3D.vertexNormal();

Upvotes: 1

Related Questions