2013-04-16 6 views
1

Я хотел бы сделать цвет участок в MATLAB, похожий на этот сюжет:Как построить равносторонний цветной треугольник?

http://1.bp.blogspot.com/-QpFb-Yj_MOg/UA4Tw3xuVVI/AAAAAAAAAIQ/T3kTUT39c-A/s1600/triangular+plot.png

Я сумел создать все точки [х, у], необходимые для того, чтобы создать вершины и у меня есть карту с цветами каждой вершины, поэтому я могу получить следующее.

Correct plot, but wrong axes

Но я не понимаю, как сделать работу оси.

код до сих пор:

% Equilateral grid 
tcorner = [0.0, 0.5,   1.0; 
      0.0, 1.0*sqrt(3)/2, 0.0]; 
tg = triangle_grid(1/0.05, tcorner); 
tgx = tg(1,:); 
tgy = tg(2,:); 

% Create triangles 
tri = delaunay(tgx,tgy); 

% Plot 
h = trisurf(tri, tgx, tgy, colorvector); 

И сеточная функция:

function triangle_grid(n, tcorner) 
    ng = ((n + 1) * (n + 2))/2; 
    tg = zeros (2, ng); 

    p = 0; 

    for i = 0 : n 
     for j = 0 : n - i 
      k = n - i - j; 
      p = p + 1; 
      tg(1:2,p) = (i * t(1:2,1) + j * t(1:2,2) + k * t(1:2,3))/n; 
     end 
    end 
end 
+0

Хорошая проблема! вы бы опубликовали код за то, что у вас есть, пожалуйста? – Acorbe

+0

@Acrobe Там вы идете с кодом :) – sehlstrom

+0

И точно вы просто хотите построить красивую диагональную ось или у вас есть проблема и с тем, что вы замышляете? – Acorbe

ответ

0

Основная проблема заключается в том, что вы не можете повернуть оси в нужное положение, потому что всегда переворачивать к нижняя сторона. Итак, вам нужно их создать.

Вот как:

% Equilateral grid 
tcorner = [0.0, 0.5, 1.0; % x 
      0.0, 1.0*sqrt(3)/2, 0.0]; % y 
tg = triangle_grid(1/0.05, tcorner); 
tgx = tg(1,:); 
tgy = tg(2,:); 

% Create triangles 
tri = delaunay(tgx,tgy); 
col = rand(size(tgx)); 
trisurf(tri,tgx,tgy,col) 
view(0,90) 
colormap('lines') 

% setting the axes: 
ax = gca; 
grid off 
ax.YAxis.Visible = 'off'; 
ticks = (0:20:80).'; 

% bottom axis: 
tickpos = linspace(tcorner(1,1),tcorner(1,3),numel(ticks)+1); 
ax.XAxis.FontSize = 14; 
ax.XAxis.TickValues = tickpos(1:end-1); 
ax.XAxis.TickLabels = ticks; 
ax.XAxis.TickLabelRotation = 45; 
xlabel('X axis title'); 

% left & right axis: 
ticksxpos = linspace(tcorner(1,1),tcorner(1,3),numel(ticks)*2+1); 
ticksypos = linspace(tcorner(2,1),tcorner(2,2),numel(ticks)+1); 
text(ticksxpos(numel(ticks)+1:-1:2)-0.03,... % left 
    ticksypos(end:-1:2)+0.03,... 
    num2str(ticks),'FontSize',14,... 
    'VerticalAlignment','bottom',... 
    'HorizontalAlignment','left',... 
    'Rotation',-45) 
text(ticksxpos(end:-1:numel(ticks)+2)+0.05,... % right 
    ticksypos(1:end-1)-0.03,... 
    num2str(ticks),'FontSize',14,... 
    'VerticalAlignment','bottom',... 
    'HorizontalAlignment','right') 
ax.Parent.Color = 'w'; 

% titles: 
text(tcorner(1,2)/2-0.06,tcorner(2,2)/2+0.06,... 
    'Left title','FontSize',14,... 
    'HorizontalAlignment','center',... 
    'Rotation',45) 
text(tcorner(1,2)+tcorner(1,2)/2+0.06,tcorner(2,2)/2+0.06,... 
    'Right title','FontSize',14,... 
    'HorizontalAlignment','center',... 
    'Rotation',-45) 

и мы получаем ...

tiangular