how can I plot the intersection of two cylinders?

11 次查看(过去 30 天)
Hi, could someone tell me how to plot only the solid formed from the intersection of two cylinders? I've already plotted a 3D graph of the two figures in the first octant, but I just wanted the intersected solid.
I've attached the code I'm using, which I took from this link :
<https://in.mathworks.com/matlabcentral/answers/93623-how-do-i-plot-the-line-of-intersection-between-two-surfaces>

采纳的回答

DGM
DGM 2021-6-5
Like everything, there are probably better ways, especially to get the edges closed. The simple way is to just plot the surfaces and truncate them. Since the mesh is rectangular, so are the truncated edges.
% parameters
r = 2;
n = 1000; % number of points per axis
% only need one cylinder
[x1 y1] = meshgrid(linspace(-r,r,n));
z1 = sqrt(r^2 - x1.^2);
z2 = -sqrt(r^2 - x1.^2);
% truncate it
m1 = x1.^2 + y1.^2 > (r+r/n)^2;
z1(m1) = NaN;
z2(m1) = NaN;
% plot it and then plot a flipped copy
opts = {'specularstrength',0.5,'ambientstrength',0.4,'diffusestrength',0.9};
surf(x1,y1,z1,opts{:}); hold on;
surf(x1,y1,z2,opts{:})
surf(x1,z1,y1,opts{:})
surf(x1,z2,y1,opts{:})
axis equal
shading flat
colormap(ccmap)
lightangle(240,60)
lighting gouraud
  1 个评论
Eduardo Fornazieri
In this case, what can I do to plot only positive values ​​of x, y, and z? (first octant). Thank you, this code is way better than mine.

请先登录,再进行评论。

更多回答(0 个)

类别

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