Why do the positions of objects in a 3D plot get mixed up when using OpenGL renderer?

1 view (last 30 days)
I have plotted a 3D cloud and inserted a plane to distinguish points before and behind the plane. However the position of the points is not correct when using OpenGL renderer. When rotating the plot I observe points located in front of the disappear while hidden points behind the plane are suddenly visible.
Changin the renderer to zBuffer can solve the issue but I would like to use OpenGL to export the plot as Vector Graphics.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 1 Oct 2009
This issue is due to the way OpenGL renderer is computing the intersection between the plane object and the 3D cloud. Surfaces are composed of smaller units called faces. The OpenGL renderer does not handle intersection of faces well. The most common reason for the intersection problem is that the faces in the surface are too large, and the intersections would occur in the middle of the faces. Increasing the number of faces in the surface (and decreasing the size of the faces) should resolve the problem, by providing face edges where the intersections can occur.
The following example will illustrate the above explanation. Note the difference when stepping through the code and rotating the view in both plots:
close all, clear all, clc;
opengl software
%%Example data
n=300;
x=rand(n,1);
y=rand(n,1);
z=rand(n,1);
%%Plot 3D cloud
figure('units','normalized','position', ...
[0.1 0.1 0.4 0.4],'renderer','opengl');
ax(1)=gca; hold on;
plot3(x(y<0.5),y(y<0.5),z(y<0.5),'r*', ...
x(y>=0.5),y(y>=0.5),z(y>=0.5),'*');
set(gca,'color','none')
%%Intersecting plane consisting of only one face object
[X1,Y1]=meshgrid(0:1,0:1);
Z1=0.5*ones(size(X1));
hs(1)=surf(X1,Z1,Y1);
colormap([1 1 1]);
title('Intersecting plane consisting of one face object')
%%View 2D
view(2)
%%Change View two 3D
view(3)
%%Plot 3D cloud
figure('units','normalized','position', ...
[0.1 0.5 0.4 0.4]);
ax(2)=gca; hold on;
plot3(x(y<0.5),y(y<0.5),z(y<0.5),'r*', ...
x(y>=0.5),y(y>=0.5),z(y>=0.5),'*');
set(gca,'color','none')
%%Many small faces
title('Many small faces')
[X2,Y2]=meshgrid(0:0.01:1,0:0.01:1);
Z2=0.5*ones(size(X2));
hold on
hs(2)=surf(X2,Z2,Y2);
colormap([1 1 1])
%%View 2D
view(2)
%%Change View two 3D
view(3)
%%Link the view properties to rotate
linkprop(ax,'view');
%%Make edges invisible
set(hs,'edgecolor','none');
%%Rotate
% to see the different placement of points before or behind the plane
for el=-15:0.5:45
view(-37,el)
pause(0.1)
end

More Answers (0)

Categories

Find more on Graphics in Help Center and File Exchange

Products


Release

R2009b

Community Treasure Hunt

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

Start Hunting!