[uniqueXY, ~, idx] = unique(data(:, 1:2), 'rows');
averageZ = zeros(size(uniqueXY, 1), 1);
for i = 1:size(uniqueXY, 1)
zValues = data(idx == i, 3);
averageZ(i) = mean(zValues);
xUnique = uniqueXY(:, 1);
yUnique = uniqueXY(:, 2);
xv = linspace(min(xUnique), max(xUnique), 100);
yv = linspace(min(yUnique), max(yUnique), 100);
[X, Y] = meshgrid(xv, yv);
Z = griddata(xUnique, yUnique, zUnique, X, Y);
[Nx, Ny, Nz] = surfnorm(X, Y, Z);
for i = 2:size(Nx, 1) - 1
for j = 2:size(Nx, 2) - 1
r3 = [Nx(i, j), Ny(i, j), Nz(i, j)];
Nx(i-1, j-1), Ny(i-1, j-1), Nz(i-1, j-1);
Nx(i-1, j), Ny(i-1, j), Nz(i-1, j);
Nx(i-1, j+1), Ny(i-1, j+1), Nz(i-1, j+1);
Nx(i, j-1), Ny(i, j-1), Nz(i, j-1);
Nx(i, j+1), Ny(i, j+1), Nz(i, j+1);
Nx(i+1, j-1), Ny(i+1, j-1), Nz(i+1, j-1);
Nx(i+1, j), Ny(i+1, j), Nz(i+1, j);
Nx(i+1, j+1), Ny(i+1, j+1), Nz(i+1, j+1);
for k = 1:size(neighbors, 1)
cosTheta = dot(r3, r4) / (norm(r3) * norm(r4));
angle = acosd(min(1, max(-1, cosTheta)));
theta(i, j) = max(theta(i, j), angle);
surf(X, Y, Z, theta, 'EdgeColor', 'none');
title('Highlighted Indented Areas Based on Normal Vector Angles');