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 commentaires

Kelly Kearney
Kelly Kearney le 18 Juin 2020
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 le 18 Juin 2020
Modifié(e) : Mammadbaghir Baghirzade le 18 Juin 2020
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

Connectez-vous pour commenter.

 Réponse acceptée

darova
darova le 19 Juin 2020
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 commentaires

Mammadbaghir Baghirzade
Mammadbaghir Baghirzade le 19 Juin 2020
Hi Darova,
Thank you for yoru reply, and the time you spent.
I assume, it should work for me. I checked the result, and I have a following question.
Does the 2D plane you cut have a curvature?
I plotted without "surf" and somehow saw the curvature on res cross-section, however I'm also curious about your answer. Did you see such a curvature on a red cross-section.
Actually the surface you cut is in 3D, why did you call it 2D, or did you mean that you cut using 2D tools?
The reason, that I am asking for curvature is, later I plan to combine all these small pieces to get a sphere. This is why I was concerning about the curvature, there should be curvature.
Thank you
Regards
Mammadbaghir Baghirzade
Mammadbaghir Baghirzade le 19 Juin 2020
And one more question.
I've just realized that I did not provide the value for "rr1" in my main question part, which should be "6.9".
May I ask, how did you understand that rr1 should be 6.9.
Thank you
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 le 19 Juin 2020
Modifié(e) : Mammadbaghir Baghirzade le 19 Juin 2020
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

Connectez-vous pour commenter.

Plus de réponses (1)

darova
darova le 20 Juin 2020

0 votes

Here is another idea using triangulation (initmesh)
  • create polygon
  • use initmesh to triangulate it
  • calculate Z coordinate
  • rotate the object

5 commentaires

Mammadbaghir Baghirzade
Mammadbaghir Baghirzade le 21 Juin 2020
Hi Darova,
Thanks a lot for your alternative suggestion.
I will accept your first answer.
The second option is also what I am looking for, I wanted to ask one thing.
I have an arc length information that I want to assign in between 2 points on the sphere.
I was thinking in which line I should provide the arc length in the script you provided in just your previous answer, namely "Untitled1.m1".
Should that be provided where the sphere is defined? I do not think so.
Thanks
Regards
Hi Darova,
I've tried to apply your alternative method to my variables.
However, there is some mismatch in the matrix dimension.
Could you please let me know if the only issue is the matrix dimension or not?
I appreciate the time your spent.
xl1 = [-3.53,-3.16,-3.16,-3.846,-3.925,-3.53];
yl1 = [-3.543,-3.359,-2.807,-2.518,-3.254,-3.543];
zl1 = [4.75355140920975,5.13239895175736,5.45391153210244,5.14567391116071,4.64928585914009,4.75355140920975];
gd = [2;length(xl1);xl1(:);yl1(:)]; % geometry description
dl = decsg(gd); % decomposition
[p,e,t] = initmesh(dl,'hmax',0.2); % triangulation
z1 = sqrt(1 - p(1,:).^2 - p(2,:).^2); % calculate Z coordinate
ff.vertices = [p' zl1(:)];
ff.faces = t(1:3,:)';
surf(x,y,z,'facecolor','none','edgecolor',[1 1 1]*0.8)
line(xl1,yl1,'linew',2)
h = patch(ff,'facecolor','g');
rotate(h,[1 0 0],30,[0 0 0]) % rotate about X
rotate(h,[0 0 1],15,[0 0 0])
darova
darova le 21 Juin 2020
try following modifications
Mammadbaghir Baghirzade
Mammadbaghir Baghirzade le 21 Juin 2020
Thank you Darova. I appreciate.
Regards
darova
darova le 22 Juin 2020

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by