how can I plot the intersection of two cylinders?

11 ビュー (過去 30 日間)
Eduardo Fornazieri
Eduardo Fornazieri 2021 年 6 月 4 日
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 Center および File ExchangeSurface and Mesh Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by