Calculate normals from nodes which generate a 3D curve

5 次查看(过去 30 天)
Hi! I have two matrices:
  • the matrix 'coord' containing the coordinates of nodes (see black nodes in the figure)
  • a matrix 'normals' having in each row the normal N=[a,b,c] (a: first column, b: second column, c: third column) for the first 10 nodes in 'coord'.
How can I determine the normals of the other nodes in 'coord' by following the trend of the nodes (red line in figure)?
load("test_pp.mat")
figure
plot3(coord(:,1),coord(:,2),coord(:,3),'k.','Markersize',20);
hold on
plot3(coord(:,1),coord(:,2),coord(:,3),'-r','LineWidth',2);
hold off
axis equal
EDIT: re-formulated question
  5 个评论
Umar
Umar 2024-8-9
Hi @ Alberto Acri,
Please see “missing code snippet” updated in my recent post.

请先登录,再进行评论。

回答(1 个)

Gayathri
Gayathri 2024-8-14
To calculate the “normals” of remaining entries in matrix “coord” we can do interpolation in 3-D space. This can be done using the function “scatteredInterpolant”. This function performs interpolation on scattered data that resides in 2-D or 3-D space. For more information, please refer the below mentioned link.
Then the new “normal” values can be found using the interpolant obtained in the above-mentioned method.
Please find the code below for your reference.
load("test_pp.mat")
known_coords=coord(1:10,:);
F_x = scatteredInterpolant(known_coords(:,1), known_coords(:,2), known_coords(:,3), normals(:,1), 'natural', 'linear');
F_y = scatteredInterpolant(known_coords(:,1), known_coords(:,2), known_coords(:,3), normals(:,2), 'natural', 'linear');
F_z = scatteredInterpolant(known_coords(:,1), known_coords(:,2), known_coords(:,3), normals(:,3), 'natural', 'linear');
% Interpolate normals for the remaining points
remaining_coords = coord(11:end, :);
interp_normals = zeros(size(remaining_coords));
for i = 1:size(remaining_coords, 1)
interp_normals(i, 1) = F_x(remaining_coords(i, 1), remaining_coords(i, 2), remaining_coords(i, 3));
interp_normals(i, 2) = F_y(remaining_coords(i, 1), remaining_coords(i, 2), remaining_coords(i, 3));
interp_normals(i, 3) = F_z(remaining_coords(i, 1), remaining_coords(i, 2), remaining_coords(i, 3));
end
% Combine known and interpolated normals
all_normals = [normals; interp_normals];
% Display results
disp(all_normals)
Hope you find this information helpful.

类别

Help CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by