Transparent plane over on object

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

采纳的回答

Chad Greene
Chad Greene 2014-6-19
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 个评论
mick777
mick777 2014-6-20
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 2014-8-16
I run into this often enough that I made a function out of it. Just type rend to toggle renderers.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by