Another question about rendering with painters
12 views (last 30 days)
I hope someone can help me with this. I need to output a 3D surface with correct depth ordering to an .eps file. The output must be in vectors. If I make the image with the opengl renderer the image will be pixel-based not vector-based. So, I need a workaround. I thought I could make my own surface grid using the painters renderer. However, the painters algorithm doesn't seem to work as it should.
The code below illustrates the problem. I make a regression surface then plot some points along the line x = y and z = max(z(:)). The result is correct (but unusable) with the opengl renderer, but wrong with the painters renderer. Given that the painters algorithm draws points from furthest to closest, with closer points overwriting further points, the grid lines should never overwrite the plot symbols, but they do.
Am I misinformed about how painters is supposed to work? Or are there settings I don't know about?
f = figure;
n = 32; % number of x and y gridlines.
x = linspace(0,400,n);
y = linspace(0,300,n);
[X, Y] = meshgrid(x, y);
z = 0 + 4*X + 2*Y; % Make a regression plane
mx = max(z(:)); % A constant height
for idx = 1:2:n
% Plot points a constant hight above 0.
h1 = plot3(x(idx), y(idx), mx, 'o');
set(h1, 'markerfacecolor', 'c', 'markeredgecolor', 'k', 'markersize', 20);
% Draw the regression plane as a bunch of line segments.
% Drawing line segments reduces ambiguity about the depth of the
% line at a given point.
for c = randperm(n-1)
for r = randperm(n-1)
% randperm is weird. However, the order in which things are drawn
% affects depth ordering when using scatter3, for some inexplicable
h2=line([x(c) x(c+1)], [y(r) y(r)], [z(r,c), z(r,c+1)]);
h3=line([x(c) x(c)], [y(r) y(r+1)], [z(r,c), z(r+1,c)]);
% Color the lines according height above 0.
set([h2, h3], 'color', [.8 .8 .8]*z(r,c)/max(z(:)));
for idx = 1:4
set(f,'renderer','opengl', 'name', 'opengl');
title('opengl', 'fontsize', 20);
set(f,'renderer','painters', 'name', 'Painters');
title('Painters', 'fontsize', 20);