Move a Point on a 3D surface
16 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Theresa Kandels
le 11 Août 2023
Commenté : Theresa Kandels
le 11 Août 2023
Hello,
I have a 3D surface with the information on the vertices and faces in a matrix. I also have a point that is located on the surface. I would like to move this point in x direction on the surface. So that I can be sure that the new point is also on the surface.
Could someone please help me with that problem?
Thank you,
Theresa
0 commentaires
Réponse acceptée
Bruno Luong
le 11 Août 2023
Modifié(e) : Bruno Luong
le 11 Août 2023
% Generate test mesh
x = 1:15; y = 1:15;
[X,Y] = meshgrid(x,y);
Z = peaks(15);
F = delaunay(X,Y);
% Your points to be projected, with moving xq constant yq
% NOTE: In your case just take the (xknown,yknown) to
% xq = xknown + 2; yq = yknown; to move them at distance 2
xq = linspace(min(x),max(x),101);
yq = 8+zeros(size(xq));
% Build some useful matrices and coordinates in arrays
xyz = [X(:) Y(:) Z(:)]';
xyzF = reshape(xyz(:,F'), 3, 3, []);
baryMat = xyzF;
baryMat(3,:,:) = 1;
figure
trisurf(F,X,Y,Z);
colormap gray
hold on
for k = 1:length(xq)
xyq = [xq(k); yq(k); 1];
w = pagemldivide(baryMat, xyq);
i = find(all(w >= 0, 1), 1); % which face contain the point
if isempty(i)
% point outside the mesh
continue
end
xyzq = xyzF(:,:,i) * w(:,:,i);
plot3(xyzq(1), xyzq(2), xyzq(3), 'g.', 'Markersize', 10)
end
3 commentaires
Bruno Luong
le 11 Août 2023
But earlier you wrote "I have a 3D surface with the information on the vertices and faces in a matrix."
So what do you have?
In my code Vertice is
xyz' % n x 3
and face is
F % m x 3
If you only have vertices you might be able to reconstruct connectivity with delaunay as I did.
Explain exactly what you have if you don't want me to guess and fail.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Surface and Mesh Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
