Building cylinder using isosurface

6 次查看(过去 30 天)
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.

采纳的回答

Matz Johansson Bergström
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 个评论
Vittorio
Vittorio 2014-7-29
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 2014-7-29
编辑:Vittorio 2014-7-29
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!

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by