Change in the gradient of points in 3D space with respect to its neighbour.
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello matlab Community,
Is there any function in Matlab to find the gradient change of a point in 3d space with respect to its neighbour point"?
I have sutface coordinates of approximately 15000 points (.STL file contains this). Now i want to find the gradient change of each point with resppecte to its neighbour.
I am attaching .STL file which contain coordinates of all the surface point.
It can be read in matlab using
TR=stlread('aggrgate_1.stl');
trimesh(TR);
0 Kommentare
Antworten (1)
Yatharth
am 3 Mai 2024
Bearbeitet: Yatharth
am 3 Mai 2024
Hi Saurav,
There is no exisiting function in MATLAB as of now (R2024a) that can find the gradient change of a point in 3D space with respect to its neighbour.
However, you can manually do it by calculating Normals for each vertex (points) and iteratively calculate the gradient change.
MATLAB's "patch" function can be used to compute normals.
Here is how you can approch the problem:
Note: I was not able to open your STL file
% Using the stl file from the below example
% openExample('matlab/ReadTriangulationFromSTLTextFileExample')
TR = stlread('tristltext.stl');
F = TR.ConnectivityList; % Faces or Connectivity List
V = TR.Points; % Vertex or Points
p = patch('Faces', F, 'Vertices', V);
% storing the normals in a matrix
normals = p.VertexNormals;
% Initialize matrix to hold gradient changes
gradientChange = zeros(size(V, 1), 1);
% Loop through each vertex
for i = 1:size(V, 1)
% Find faces that include this vertex (row indices of a vertix in F)
[row, ~] = find(F == i);
% Find unique vertices connected to those faces, excluding the current vertex
neighbors = unique(F(row,:));
neighbors(neighbors == i) = [];
% Calculate the difference between the current vertex and its neighbors
% Here, we simply calculate the Euclidean distance as a proxy for gradient change
diffs = sqrt(sum((V(i,:) - V(neighbors,:)).^2, 2));
% Store the mean difference (or choose another metric)
gradientChange(i) = mean(diffs);
end
disp(gradientChange);
Gradient change for each point/ vertex is stored in the gradientChange matrix.
5 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!