crop the polygon from the 3D surface
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mammadbaghir Baghirzade
el 18 de Jun. de 2020
Editada: Mammadbaghir Baghirzade
el 10 de Nov. de 2020
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 comentarios
Kelly Kearney
el 18 de Jun. de 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
el 18 de Jun. de 2020
Editada: Mammadbaghir Baghirzade
el 18 de Jun. de 2020
Respuesta aceptada
darova
el 19 de Jun. de 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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/318940/image.png)
4 comentarios
Kelly Kearney
el 19 de Jun. de 2020
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
el 19 de Jun. de 2020
Editada: Mammadbaghir Baghirzade
el 19 de Jun. de 2020
Más respuestas (1)
darova
el 20 de Jun. de 2020
Here is another idea using triangulation (initmesh)
- create polygon
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/319405/image.png)
- use initmesh to triangulate it
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/319408/image.png)
- calculate Z coordinate
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/319411/image.png)
- rotate the object
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/319414/image.png)
5 comentarios
Ver también
Categorías
Más información sobre Surface and Mesh Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!