# Change in the gradient of points in 3D space with respect to its neighbour.

7 visualizzazioni (ultimi 30 giorni)
Saurav il 23 Apr 2024
Commentato: Saurav il 21 Mag 2024 alle 5:35
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
trimesh(TR);
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposte (1)

Yatharth il 3 Mag 2024
Modificato: Yatharth il 3 Mag 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
F = TR.ConnectivityList; % Faces or Connectivity List
Unable to resolve the name 'TR.ConnectivityList'.
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
% 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)
end
Gradient change for each point/ vertex is stored in the gradientChange matrix.
Here is the link to the "patch" function : https://www.mathworks.com/help/matlab/ref/patch.html
##### 5 CommentiMostra 3 commenti meno recentiNascondi 3 commenti meno recenti
Saurav il 6 Mag 2024
Modificato: Saurav il 10 Mag 2024
Hello Yatharth
Currently above code is giving local gradient Question1. How we can get global gradient change using those local gradient change.
Qustion2: How many neighbor of a vertices is considering in above code??. for example it considered 4 neighbor, 8 neighbor or 12 neighbor points of each vertices.
Issue: I am not geting same consistency in case of sphere.stl. I have attached sphere stl file also.
Saurav il 21 Mag 2024 alle 5:35
Hello @Yatharth
Above all problem i resolved. I have one question regarding sphere.
For sphere it is not giving zero or lesser value as compared to Icosahedron.
Kindly hep me out for this.
I have attached sphere stl in abpove comment.

Accedi per commentare.

### Categorie

Scopri di più su STL (STereoLithography) in Help Center e File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by