フィルターのクリア

Transparency tube section like alpha function

7 ビュー (過去 30 日間)
Maximilian
Maximilian 2014 年 8 月 22 日
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 件のコメント
Lateef Adewale Kareem
Lateef Adewale Kareem 2015 年 6 月 26 日
%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

サインインしてコメントする。

回答 (2 件)

Mike Garrity
Mike Garrity 2014 年 8 月 22 日
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 件のコメント
Maximilian
Maximilian 2014 年 9 月 4 日
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?

サインインしてコメントする。


Mike Garrity
Mike Garrity 2014 年 9 月 4 日
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.

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by