Transparent plane over on object

조회 수: 10 (최근 30일)
mick777
mick777 2014년 6월 19일
댓글: Chad Greene 2014년 8월 16일
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