Move a Point on a 3D surface

16 ビュー (過去 30 日間)
Theresa Kandels
Theresa Kandels 2023 年 8 月 11 日
コメント済み: Theresa Kandels 2023 年 8 月 11 日
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

採用された回答

Bruno Luong
Bruno Luong 2023 年 8 月 11 日
編集済み: Bruno Luong 2023 年 8 月 11 日
% 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 件のコメント
Bruno Luong
Bruno Luong 2023 年 8 月 11 日
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 2023 年 8 月 11 日
Thank you for your answer, this will help!
I'm sorry I'm still very new to this subject.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

タグ

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by