Plot only the surfaces within a bounding surface?
古いコメントを表示
I have a large cylinder with base in the x-y plane intersected by smaller cylinders with base in the x-z plane. I'd like to plot only the surfaces belonging to the larger cylinder, however my smaller cylinder sticks out of the larger volume. How can I make the surface of the small cylinder bounded by the large cylinder?

Below is the code.
rs = 9.0;
Cxt = -6.0;
Czt = 3.0;
dia_tube = 1.0;
% for the larger cylinder plotting
[xs1 ys1] = GetCircle(rs, 0, 0, 0, 2*pi);
Ns = length(xs1);
zmins = zeros(1,Ns);
zmaxs = zeros(1,Ns) + 6;
xs = [xs1;xs1];
ys = [ys1;ys1];
zs = [zmins;zmaxs];
surf(xs,ys,zs);
alpha 0.5;
hold on
% for smaller cylinder(s)
[xt zt] = GetCircle(dia_tube*0.5, Cxt, Czt, 0, 2*pi);
for i = 1:Ns
ymin = -(rs^2 - xt(i)^2)^(1/2);
ymax = (rs^2 - xt(i)^2)^(1/2);
end
xt = [xt;xt];
yt = [ymin;ymax];
zt = [zt;zt];
surf(xt,yt,zt);
axis equal
% with the circle generator
function [x y] = GetCircle(r, h, k, a, b)
t = linspace(a, b, 40);
x = r*cos(t) + h;
y = r*sin(t) + k;
end
I was hoping ymin and ymax would allow me to do this, but we just find the min and max of the x data such that the edge of the tubes are aligned.
I also tried changing
yt = [ys1;ys1];
to match the cylinder case, but this left me with a weird 2D shape. Thanks for your help.
採用された回答
その他の回答 (1 件)
hello
seems to me there is no need for a for loop to compute ymin & ymax
also ymin = - ymax , so we can avoid creating yet another variable in the workspace
and ymax can be directly computed as
ymax = (rs^2 - (abs(Cxt)+0.5*dia_tube)^2)^(1/2);
final result :
rs = 9.0;
Cxt = -6.0;
Czt = 3.0;
dia_tube = 1.0;
% for the larger cylinder plotting
[xs1, ys1] = GetCircle(rs, 0, 0, 0, 2*pi);
Ns = length(xs1);
zmins = zeros(1,Ns);
zmaxs = zeros(1,Ns) + 6;
xs = [xs1;xs1];
ys = [ys1;ys1];
zs = [zmins;zmaxs];
surf(xs,ys,zs);
alpha 0.5;
hold on
% for smaller cylinder(s)
[xt, zt] = GetCircle(dia_tube*0.5, Cxt, Czt, 0, 2*pi);
ymax = (rs^2 - (abs(Cxt)+0.5*dia_tube)^2)^(1/2);
xt = [xt;xt];
yt = [ymax;-ymax];
zt = [zt;zt];
surf(xt,yt,zt);
axis equal
% with the circle generator
function [x, y] = GetCircle(r, h, k, a, b)
t = linspace(a, b, 40);
x = r*cos(t) + h;
y = r*sin(t) + k;
end
カテゴリ
ヘルプ センター および 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!



