crop the polygon from the 3D surface

조회 수: 6 (최근 30일)
Mammadbaghir Baghirzade
Mammadbaghir Baghirzade 2020년 6월 18일
편집: Mammadbaghir Baghirzade 2020년 11월 10일
Hi all,
I have such an attached 3D surface and a polygon on it. (Code is provided below)
I aim to crop the portion which is only inside the polygon and delete everything outside the polygon.
I found out the function of "inpolygon", but it did not work well enough since it is for 2D.
Then I encountered with "inpolyhedron" which is written for 3D, but was not that successfull on using it.
Is there any other way that you would suggest?
Thank you
Regards
  댓글 수: 2
Kelly Kearney
Kelly Kearney 2020년 6월 18일
It's difficult to tell from the picture... does all the data (both the surface and polygon) fall along a single plane?
Mammadbaghir Baghirzade
Mammadbaghir Baghirzade 2020년 6월 18일
편집: Mammadbaghir Baghirzade 2020년 6월 18일
Hi Kelly,
Thank you for your reply.
Yes, there are 5 points on the surface and then I joined those points with lines.
So, both of the polygon and the surface are on the same plane.
I've provided the script in the main question part.
Thanks you
Regards

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

채택된 답변

darova
darova 2020년 6월 19일
What about this? I just cutted surface in 2d plane
[X1,Y1,Z1] = sph2cart(llambda1,pphi1,6.9);
surf(X1,Y1,Z1)
in = inpolygon(X1,Y1,xl1,yl1);
view(3);
hold on
plot3(X1(in),Y1(in),Z1(in),'.r')
plot3(xl1, yl1, zl1,'MarkerSize',14, 'Color','red')
axis vis3d
  댓글 수: 4
Kelly Kearney
Kelly Kearney 2020년 6월 19일
Darova beat me to the answer...
Your points don't actually fall on a plane, but rather on a lightly-curved surface. You can crop the data as desired by projecting in onto a 2D plane. That's what Darova's call to inpolygon does, by ignoring the z-coordinates... projects the surface and polygon coordinates onto the XY plane.
And as to how they figured out rr1 = 6.9, if one assumes the polygon vertices fall on the same surface:
[~,~,r] = cart2sph(xl1,yl1,zl1)
r =
6.9 6.9 6.9 6.9 6.9 6.9
Mammadbaghir Baghirzade
Mammadbaghir Baghirzade 2020년 6월 19일
편집: Mammadbaghir Baghirzade 2020년 6월 19일
Hi Kelly,
Thanks for your explanations, I understand.
Do you know how can I connect those points (vertices of a polygon) with an arc instead of a line.
I mean , now I understand better what you meant by asking if the surface and the polygon are on the same plane or not.
Atually I want to crop the portion which looks like a polygon from the surface, so I need to have the curvature.
In this case, I assume there is not a curvature, do you agree with me?
Thanks
Regards

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

추가 답변 (1개)

darova
darova 2020년 6월 20일
Here is another idea using triangulation (initmesh)
  • create polygon
  • use initmesh to triangulate it
  • calculate Z coordinate
  • rotate the object
  댓글 수: 5
Mammadbaghir Baghirzade
Mammadbaghir Baghirzade 2020년 6월 21일
Thank you Darova. I appreciate.
Regards
darova
darova 2020년 6월 22일

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

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by