how can I plot the intersection of two cylinders?

조회 수: 5 (최근 30일)
Eduardo Fornazieri
Eduardo Fornazieri 2021년 6월 4일
댓글: Eduardo Fornazieri 2021년 6월 5일
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
Eduardo Fornazieri 2021년 6월 5일
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