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

KALYAN ACHARJYA
KALYAN ACHARJYA 2020년 4월 18일
Can you share the code, so that add the code for "3 random points for trangle"?
John D'Errico
John D'Errico 2020년 4월 18일
Is the surface a curved one? If so, then essentially 50% of the time (depending on the local shape of the surface), that triangle will not be visible, as it will be sunk below, under the hidden side of the surface.
If you wish to draw some triangle that will ALWAYS be visible, then you will need to make the surface translucent. This is not that difficult to do in MATLAB, use the 'FaceAlpha' property of the resulting surface. Set it to some value less than 1.
If you wish to draw a triangle with curved edges that exactly follow the contour of any curved (but triangularly faceted) surface, then drawing lines along the surface? You would then need to compute that set of three segmented lines through the surface, along the curved "edges" of the triangle. It can be done of course, but for that, you would need to write explicit code to exactly find those linear segments, thus where the path crosses the edge of each triangle in the surface. It is doable, since I've done it at least twice before.
Jerry
Jerry 2020년 4월 18일
편집: Jerry 2020년 4월 18일
Yes, the surface is curved. I don't have a code yet, just the surface and the coordinates of the three corner points of my triangle.
how do I find the linear segments, do you have any description or source on how I can do this?
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일

0 개 추천

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일
how do I draw the shape afterwards?
darova
darova 2020년 4월 19일
Do you know what is this?
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')

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

카테고리

질문:

2020년 4월 18일

댓글:

2020년 8월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by