Move a Point on a 3D surface

10 visualizaciones (últimos 30 días)
Theresa Kandels
Theresa Kandels el 11 de Ag. de 2023
Comentada: Theresa Kandels el 11 de Ag. de 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

Respuesta aceptada

Bruno Luong
Bruno Luong el 11 de Ag. de 2023
Editada: Bruno Luong el 11 de Ag. de 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 comentarios
Bruno Luong
Bruno Luong el 11 de Ag. de 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.
Theresa Kandels
Theresa Kandels el 11 de Ag. de 2023
Thank you for your answer, this will help!
I'm sorry I'm still very new to this subject.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by