Building cylinder using isosurface

3 visualizaciones (últimos 30 días)
Vittorio
Vittorio el 29 de Jul. de 2014
Editada: Vittorio el 29 de Jul. de 2014
Hello everyone,
I'm trying to create a cylindric patch using the isosurface command. Using this tutorial I created my own structure. The code is the following:
[x,y,z] = meshgrid(-1:.02:1);
blob = z <= 0 & z >= -1 & x.^2 + y.^2 <= sqrt(0.18) & x.^2 + y.^2 >= sqrt(0.15);
p = patch(isosurface(blob,0.5));
set(p, 'FaceColor', 'red', 'EdgeColor', 'none');
view(3)
camlight
alpha(0.3)
lighting gouraud
Now, I want to specify for every level of the cylinder a different radius. The values of the radii for every level are stored in a vector 1x36.
How can I modify the blob accordingly?
Thanks for any suggestions.

Respuesta aceptada

Matz Johansson Bergström
Matz Johansson Bergström el 29 de Jul. de 2014
I would try using a function
test = @(x) abs( cos(4*x) );
[x,y,z] = meshgrid(-1:.02:1);
blob = z <= 0 & z >= -1 & x.^2 + y.^2 <= ...
sqrt(0.18*test(z)) & x.^2 + y.^2 >= ...
sqrt(0.12*test(z));
In this way you will get a wobbly thing depending on the z coordinate.
  2 comentarios
Vittorio
Vittorio el 29 de Jul. de 2014
Good solution, but the radius is not changing accordingly to a function. The vector which is storing the radii values is:
r= 0.8833
0.9992
0.9920
0.8994
0.9213
0.9256
0.9311
0.9688
0.9909
0.9581
0.9924
0.9662
0.8900
0.9727
0.9975
0.9872
0.9791
1.0000
0.9717
0.9591
0.9762
0.9823
0.9599
0.9682
0.9459
0.9369
0.9260
0.8894
0.9451
0.9615
0.9598
0.9837
0.9804
0.9739
0.9734
0.9735
Vittorio
Vittorio el 29 de Jul. de 2014
Editada: Vittorio el 29 de Jul. de 2014
I did it! :)
Probably not an elegant solution, but here is the code:
i = 1;
[x,y,z] = meshgrid(-1:.02:1);
r1 = zeros(length(z),length(z),length(z));
step = round(length(z)/length(r));
for j = 1:step:length(z)
r1(:,:,j) = r(i);
if j+1>length(z)
break
end
r1(:,:,j+1) = r(i);
if j+2>length(z)
break
end
r1(:,:,j+2) = r(i);
if i>length(r)
break
end
i = i+1;
end
blob = z <= 0 & z >= -1 & x.^2 + y.^2 <= sqrt(0.18*r1) & x.^2 + y.^2 >= ...
sqrt(0.12*r1);
p = patch(isosurface(blob,0.5));
set(p, 'FaceColor', 'red', 'EdgeColor', 'none');
view(3)
camlight
alpha(0.3)
lighting gouraud
Thanks for your tip!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Lighting, Transparency, and Shading en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by