Borrar filtros
Borrar filtros

Transparency tube section like alpha function

7 visualizaciones (últimos 30 días)
Maximilian
Maximilian el 22 de Ag. de 2014
Comentada: Lateef Adewale Kareem el 26 de Jun. de 2015
Hi!
I wrote a function, which is able to draw a various 3D-cylinder. My problem is, that I want to see the flow of sensors in that tube.
I'm searching for an idea or a function which makes just a section of my tube transparent (e.g. the front side).I found the matlab-function alpha, but this makes my whole tube transparent.
Hope you can help me. Max
  1 comentario
Lateef Adewale Kareem
Lateef Adewale Kareem el 26 de Jun. de 2015
%after generating the XYZ coordinates of the tube you use
s = surf(X,Y,Z); %plot set(s,'FaceColor','b','FaceAlpha',0.2); % setting color and transparency

Iniciar sesión para comentar.

Respuestas (2)

Mike Garrity
Mike Garrity el 22 de Ag. de 2014
Assuming you're using surf, perhaps like something this:
[a,b]=meshgrid(linspace(0,pi/2,25),linspace(0,2*pi,40));
r1=2;
r2=1;
x=cos(a).*(r1+r2*cos(b));
y=sin(a).*(r1+r2*cos(b));
z=r2*sin(b);
h=surf(x,y,z);
Then you can set the AlphaData to make a portion transparent, like this:
adata=ones(size(z));
adata(20:30,10:15)=.25;
set(h,'FaceColor','interp','FaceAlpha','interp','AlphaData',adata)
  1 comentario
Maximilian
Maximilian el 4 de Sept. de 2014
Thanks, that helps me a bit!
But now I have a new little problem. I've no idea, how to change the adata-values: adata(20:30,10:15)=.25; I think they depend on my surf-values.
If i scale them too high, Matlab says me: "Warning: size(AlphaData) must equal size(ZData) for interpolated alpha"
What can I do?

Iniciar sesión para comentar.


Mike Garrity
Mike Garrity el 4 de Sept. de 2014
What that's saying is that the size of your AlphaData array isn't the same as the size of your ZData array. They need to match so that you have one value for each vertex. These two commands should always return the same thing.
size(get(h,'ZData'))
size(get(h,'AlphaData'))
Perhaps when you indexed into the adata array to insert your lower alpha values, you indexed off the end of the array. If you do that, then MATLAB will stretch the array to make room for the new values. For example, if I change the example above to this:
adata=ones(size(z));
adata(20:100,10:15)=.25;
Then adata will be larger than z. Then it can't be used as the AlphaData array, because the size doesn't match.
Basically, you want AlphaData to be an array which is the same size as ZData and contains a number between 0 and 1 in each element. A value of 1 will be completely opaque, a value of 0 will be totally transparent, and a value in between will have a transparency in between.

Categorías

Más información sobre Surface and Mesh Plots 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