Calculate normals from nodes which generate a 3D curve

조회 수: 5 (최근 30일)
Alberto Acri
Alberto Acri 2024년 8월 2일
답변: Gayathri 2024년 8월 14일
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
Alberto Acri
Alberto Acri 2024년 8월 9일
missing code snippet
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