Draw triangle on 3d mesh

6 ビュー (過去 30 日間)
Jerry
Jerry 2020 年 4 月 18 日
コメント済み: Steven Lord 2020 年 8 月 21 日
Hi, I have an irregualar 3d surface plot build just with faces and vertices. Now I want to select 3 random points from the plot and automatically draw a triangle with these corner points on top of the surface (so that the triangle nestles on the given 3D surface).
  5 件のコメント
Jerry
Jerry 2020 年 4 月 19 日
please help
Steven Lord
Steven Lord 2020 年 8 月 21 日
This is a copy of the original question in case it gets edited away like this one.
"Hi, I have an irregualar 3d surface plot build just with faces and vertices. Now I want to select 3 random points from the plot and automatically draw a triangle with these corner points on top of the surface (so that the triangle nestles on the given 3D surface)."

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

回答 (1 件)

darova
darova 2020 年 4 月 19 日
What about this?
function main
opengl software
h = surf(sphere(20));
axis vis3d
set([h gcf],'hittest','off') % не знаю почему
set(gca,'buttondownfcn',@func) % клацать только на 'axes'
function func(hobj,hev)
p = get(hobj,'currentpoint');
p
line(p(:,1),p(:,2),p(:,3),'marker','o')
  4 件のコメント
Jerry
Jerry 2020 年 4 月 19 日
no, unfortunately I don't
darova
darova 2020 年 4 月 19 日
編集済み: darova 2020 年 4 月 19 日
I want to explain you how does it work: you can't choose points you want directly. But you can pick some point and then calculate distances from this point to every existing points on plot. Having smallest distance using min you can choose closest point
Here is a simple script
x = rand(20,1);
y = rand(20,1);
plot(x,y,'.b')
p = ginput(1);
[~,ix] = min(pdist2(p,[x y]));
line(x(ix),y(ix),'marker','o')

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

カテゴリ

Help Center および File ExchangeGraphics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by