how can I plot the intersection of two cylinders?
5 次查看(过去 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>
0 个评论
采纳的回答
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!