Transparent plane over on object

10 views (last 30 days)
mick777
mick777 on 19 Jun 2014
Commented: Chad Greene on 16 Aug 2014
Can anyone please explain to me what am I doing wrong here. I plan to have a transparent plane over the 3d object(cylinder), I have tried all possible methods to define the plane and set the transparency using alpha parameter but the plane ends up being a solid color. The code only for the transparent plane works fine until I plot it along with the object. Here is a Snippet of my code:
plot my_3dobject; %plot command for my 3d object
%code to define and plot the transparent plane using three reference points
pointA = [0,0,0];
pointB = [-4,0,0];
pointC = [4,0,4];
normal = cross(pointA-pointB, pointA-pointC); %# Calculate plane normal
%# Transform points to x,y,z
xx = [pointA(1) pointB(1) pointC(1)];
yy = [pointA(2) pointB(2) pointC(2)];
zz = [pointA(3) pointB(3) pointC(3)];
%Find all coefficients of plane equation
A = normal(1); B = normal(2); C = normal(3);
D = -dot(normal,pointA);
%Decide on a suitable showing range
xLim = [min(xx) max(xx)];
zLim = [min(zz) max(zz)];
[X,Z] = meshgrid(xLim,zLim);
Y = (A * X + C * Z + D)/ (-B);
reOrder = [1 2 4 3];
v = patch(X(reOrder),Y(reOrder),Z(reOrder),'g');
set(v,'facealpha',0.1);
set(v,'edgealpha',0.1);
Any pointers/suggestions will be really helpful. Thank you

Accepted Answer

Chad Greene
Chad Greene on 19 Jun 2014
I can think of two possible problems. If you're plotting the object after plotting the plane, the plane will disappear if you don't use the hold on command before plotting the object. The other possible issue is the figure renderer. Try each of the following:
set(gcf,'renderer','opengl')
If that doesn't work, try
set(gcf,'renderer','zbuffer')
and if that doesn't work try
set(gcf,'renderer','painters')
Hope this helps.
  2 Comments
mick777
mick777 on 20 Jun 2014
Thanks for having taken the time to reply Chad, I made a few changes to the code and was able to get it. The set(gcf,'renderer','opengl') command worked just fine. Thanks once again
plot my_3dobject; %plot command for my 3d object
hold on;
threshold = 0;
% Obtain the limits of the axes
%zp = get(gca,'Zlim');
zp = [0.5 4];
xp = get(gca,'Xlim');
% Use the axes x and Y limits to find the co-ordinates for the patch
x1 = [ xp(1) xp(2) xp(2) xp(1)];
z1 = [ zp(1) zp(1) zp(2) zp(2)];y1 = ones(1,numel(z1))* threshold;
v = patch(x1,y1,z1, 'g');
set(v,'facealpha',0.1);
set(v,'edgealpha',0.1);
set(gcf,'renderer','opengl') ;
hold on;
Chad Greene
Chad Greene on 16 Aug 2014
I run into this often enough that I made a function out of it. Just type rend to toggle renderers.

Sign in to comment.

More Answers (0)

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!