Another question about rendering with painters
41 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
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?
Thanks, Rick
close all;
clear all;
f = figure;
set(f,'renderer','Painters');
view(-40, 20);
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
hold on;
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);
end
% 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
% reason.
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(:)));
end
end
grid on;
for idx = 1:4
set(f,'renderer','opengl', 'name', 'opengl');
title('opengl', 'fontsize', 20);
pause(2);
set(f,'renderer','painters', 'name', 'Painters');
title('Painters', 'fontsize', 20);
pause(2);
end
0 commentaires
Réponses (1)
Walter Roberson
le 13 Sep 2016
I suggest you have a look at the File Exchange contribution export_fig which supports vector output in some circumstances (SVG files at least; not sure about others.)
3 commentaires
Walter Roberson
le 13 Sep 2016
If I recall, with the correct options, export_fig will generate in vector format.
Voir également
Catégories
En savoir plus sur Printing and Saving dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!