Plot only the surfaces within a bounding surface?

6 visualizaciones (últimos 30 días)
iontrap
iontrap el 30 de Mayo de 2023
Comentada: Mathieu NOE el 31 de Mayo de 2023
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.

Respuesta aceptada

iontrap
iontrap el 31 de Mayo de 2023
Editada: iontrap el 31 de Mayo de 2023
I was able to figure out the solution:
[xt zt] = GetCircle(dia_tube*0.5, Cxt, Czt, 0, 2*pi); %% make a circle for the small cylinder
for i = 1:Ns
y_temp(i) = sqrt(rs^2 - (xt(i))^2); %% the y value belonging to the large cylinder corresponding to a given x value of small cylinder.
end
xt3 = [xt;xt]; %% change this to a different variable for clarity.
yt3 = [y_temp;-y_temp];
zt3 = [zt;zt];
surf(xt3,yt3,zt3);
gives the result -
  3 comentarios
iontrap
iontrap el 31 de Mayo de 2023
Great! Thanks for your help.
Mathieu NOE
Mathieu NOE el 31 de Mayo de 2023
my pleasure !

Iniciar sesión para comentar.

Más respuestas (1)

Mathieu NOE
Mathieu NOE el 31 de Mayo de 2023
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
  1 comentario
iontrap
iontrap el 31 de Mayo de 2023
Thanks for your response. The reason I tried to use a loop was to create a curved bounding surface rather than a planar bounding surface. There is still the problem shown in the attached picture.

Iniciar sesión para comentar.

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by