Translate 3D coordinates on a known surface

Hi. I would like to know if there is a way to translate each 3D coordinate (blue dots) such that they lie on a known red surface.
Below is the code:
Nodes_XFix = load("Nodes_XFix.mat");
Nodes_XFix = Nodes_XFix.Nodes_XFix;
Faces_XFix = load("Faces_XFix.mat");
Faces_XFix = Faces_XFix.Faces_XFix;
coord_XMov = load("coord_XMov.mat");
coord_XMov = coord_XMov.coord_XMov;
figure
plot3(Nodes_XFix(:,1), Nodes_XFix(:,2), Nodes_XFix(:,3),'r.','Markersize',12)
hold on
trimesh(Faces_XFix(:,:),Nodes_XFix(:,1),Nodes_XFix(:,2),Nodes_XFix(:,3),'EdgeColor','r','Linewidth',1,'Facecolor','w')
plot3(coord_XMov(:,1), coord_XMov(:,2), coord_XMov(:,3),'b.','Markersize',12)
hold off
grid off
axis equal
xlabel('x')
ylabel('y')
zlabel('z')
view([15,50,30])

댓글 수: 7

I know I've told you this before but, if you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
We'll check back later for your attached data and screenshots of your plot(s).
Alberto Acri
Alberto Acri 2023년 1월 14일
편집: Alberto Acri 2023년 1월 14일
Sorry! I forgot to attach the files!
What do you want to do with them?
LD1 = load(websave('','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1263470/Nodes_XFix.mat'));
Nodes_XFix = LD1.Nodes_XFix;
LD2 = load(websave('','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1263465/Faces_XFix.mat'));
Faces_XFix = LD2.Faces_XFix;
LD3 = load(websave('','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1263475/coord_XMov.mat'));
coord_XMov = LD3.coord_XMov;
figure
scatter3(Nodes_XFix(:,1), Nodes_XFix(:,2), Nodes_XFix(:,3), 50, 'r.', 'MarkerFaceAlpha',0.5)
hold on
trimesh(Faces_XFix(:,:),Nodes_XFix(:,1),Nodes_XFix(:,2),Nodes_XFix(:,3),'EdgeColor','r','Linewidth',1,'Facecolor','w')
plot3(coord_XMov(:,1), coord_XMov(:,2), coord_XMov(:,3),'b.','Markersize',12)
hold off
grid off
axis equal
xlabel('x')
ylabel('y')
zlabel('z')
view([15,50,30])
.
I would like the blue coordinates to be positioned on the red triangular surface.
Matt J
Matt J 2023년 1월 14일
Hi. I would like to know if there is a way to translate each 3D coordinate (blue dots) such that they lie on a known red surface.
Do all the blue points have to translate as a single rigid body, or do they all translate independently of each other? If the latter, which point on the red surface should a blue point move to? The closest point?
Do all the blue points have to translate as a single rigid body, or do they all translate independently of each other?
Each blue dot must move independently of each other.
If the latter, which point on the red surface should a blue point move to? The closest point?
Yes, each blue dot must move across the red surface to the nearest point.
Matt J
Matt J 2023년 1월 15일
In future, please consolidate your variables into a single .mat file, as I have done here. This reduces the amount of work needed for us to download and import all your variables.

댓글을 달려면 로그인하십시오.

 채택된 답변

Matt J
Matt J 2023년 1월 16일

0 개 추천

댓글 수: 4

Hi! Thank you for your reply.
I tried using this code, but I am not sure if the input data is correct. Could you please check the code below?
Nodes_XFix = load("Nodes_XFix.mat");
Nodes_XFix = Nodes_XFix.Nodes_XFix;
Faces_XFix = load("Faces_XFix.mat");
Faces_XFix = Faces_XFix.Faces_XFix;
coord_XMov = load("coord_XMov.mat");
coord_XMov = coord_XMov.coord_XMov;
[faces2, vertices2] = point2trimesh(Faces_XFix, Nodes_XFix, 'QueryPoints', coord_XMov);
figure
plot3(Nodes_XFix(:,1), Nodes_XFix(:,2), Nodes_XFix(:,3),'r.','Markersize',12)
hold on
trimesh(Faces_XFix(:,:),Nodes_XFix(:,1),Nodes_XFix(:,2),Nodes_XFix(:,3),'EdgeColor','r','Linewidth',1,'Facecolor','w')
plot3(vertices2(:,1), vertices2(:,2), vertices2(:,3),'b.','Markersize',30)
hold off
grid off
axis equal
xlabel('x')
ylabel('y')
zlabel('z')
view([15,50,30])
because I am getting the following error:
Error using point2trimesh
Expected a string scalar or character vector for the parameter name.
Error in point2trimesh (line 127)
parser.parse(varargin{:});
I think it should be,
[faces2, vertices2] = point2trimesh('Faces',Faces_XFix,...
'Vertices',Nodes_XFix,...
'QueryPoints', coord_XMov);
Yes it works!
I also tried with another dataset (closed surface) however it gives me the following "warning":
Warning: Some input points are not referenced by the triangulation.
Do you have any idea how to solve it?
Matt J
Matt J 2023년 1월 17일
I don't. Like I said, I've never used it before. It might help to see the complete warning message, though.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Matt J
Matt J 2023년 1월 15일

1 개 추천

[~,I]=pdist2( Nodes_XFix, coord_XMov,'euc','Smallest',1)
coord_XMov = Nodes_XFix(I,:);

댓글 수: 2

Thank you for your reply @Matt J! I observed that each blue point moves to the nearest red point.
Is there a possibility to move the blue points also on the surface of the triangles (red mesh) and not only on the vertices ? See, for example, the green dots in the figure below:
Matt J
Matt J 2023년 1월 16일
편집: Matt J 2023년 1월 16일
It's going to be a lot more computation. Are you sure you need a rigorous projection? Obviously as the mesh gets finer, the difference diminishes.

댓글을 달려면 로그인하십시오.

카테고리

제품

릴리스

R2021b

질문:

2023년 1월 14일

댓글:

2023년 1월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by