Transparency tube section like alpha function
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Lateef Adewale Kareem
am 26 Jun. 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
Antworten (2)
Mike Garrity
am 22 Aug. 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)
Mike Garrity
am 4 Sep. 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.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Surface and Mesh Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!