0

I have a very simple function composed of two planes in the unit triangle. I managed to plot this function by parameterizing the coordinates. Now that I have the function, I would like to see how it looks like when multiplied with the polynomials, but then I get unexpected results. This is what I get

enter image description here

The middle result is when I multiply the function by 1-x-y and the second one by simply multiplying by x.

and this is the MWE:

\documentclass[border={10pt 10pt 10pt 10pt}]{standalone}

\usepackage[usenames,dvipsnames,svgnames,table]{xcolor} % use color
\usepackage{tikz}
\usepackage{pgfplots}

\usetikzlibrary{pgfplots.groupplots, backgrounds}

\begin{document}
\begin{tikzpicture}[
  declare function={upper(\x,\y) = \x + \y*(1-2*\x);},
  declare function={lowerl(\x,\y)= \x + \y*(1-2*\x);},
  declare function={lowerr(\x,\y)= \x + \y*(1-2*\x);},
]
  
\begin{groupplot}[
    group style={
        group size=3 by 1,
    },
        xmin=0,xmax=1,
        ymin=0,ymax=1,
        view={-30}{65},
        axis line style={draw=none},
        tick style={draw=none},
        ticks=none,
        ]
        
\nextgroupplot[unbounded coords=jump,clip=false, variable=x,
        variable y=y,]

\addplot3[patch,patch type=triangle,color=gray,faceted color=gray,fill opacity=0.1] coordinates {(0,0,0) (1,0,0) (0,1,0)};
\addplot3[opacity=0.7,
     samples=2, samples y=2,
     domain=0:0.5, domain y=0:1,
     colormap/blackwhite, shader=interp, surf, z buffer=sort
 ] ({x},{upper(x,y)},{x}); 
\addplot3[opacity=0.7,
     samples=2, samples y=2,
     domain=0:0.5, domain y=0:0.5,
     colormap/blackwhite, shader=interp, surf, z buffer=sort
 ] ({lowerl(x,y)},{y}, {y} );
\addplot3[opacity=0.7,
     samples=2, samples y=2,
     domain=0.5:1, domain y=0:0.5,
     colormap/blackwhite, shader=interp, surf, z buffer=sort
 ] ({lowerr(x,y)}, {y}, {y} );
%% lines
\addplot3[dashed, samples y=1,
    samples=2, domain=0:1
]({0.5}, {0.5}, {x/2});
\addplot3[gray, samples y=1,
    samples=101, domain=0:0.5
]({x}, {x}, {x});
\addplot3[gray, samples y=1,
    samples=2, domain=0:0.5
]({0.5}, {x}, {x});
\addplot3[dotted, samples y=1,
    samples=2, domain=0:0.5
]({0.5}, {x}, {0});
\addplot3[dotted, samples y=1,
    samples=2, domain=0:0.5
]({x}, {x}, {0});


\nextgroupplot[unbounded coords=jump,clip=false, variable=x,
        variable y=y,zmax=0.1]

%% background element
\addplot3[patch,patch type=triangle,color=gray,faceted color=gray,fill opacity=0.1] coordinates {(0,0,0) (1,0,0) (0,1,0)};
%% surfaces
\addplot3[opacity=0.7,
     samples=20, samples y=20,
     domain=0:0.5, domain y=0:1,
     colormap/blackwhite, shader=interp, surf, z buffer=sort
 ] ({x},{upper(x,y)},{x*(1-x-y)}); 
\addplot3[opacity=0.7,
     samples=20, samples y=20,
     domain=0:0.5, domain y=0:0.5,
     colormap/blackwhite, shader=interp, surf, z buffer=sort
 ] ({lowerl(x,y)},{y}, {y*(1-x-y)} );
\addplot3[opacity=0.7,
     samples=20, samples y=20,
     domain=0.5:1, domain y=0:0.5,
     colormap/blackwhite, shader=interp, surf, z buffer=sort
 ] ({lowerr(x,y)}, {y}, {y*(1-x-y)} );
%%% lines
%\addplot3[dashed, samples y=1,
%    samples=2, domain=0:1
%]({0.5}, {0.5}, {x/2});
%\addplot3[gray, samples y=1,
%    samples=101, domain=0:0.5
%]({x}, {x}, {x});
%\addplot3[gray, samples y=1,
%    samples=2, domain=0:0.5
%]({0.5}, {x}, {x});
%\addplot3[dotted, samples y=1,
%    samples=2, domain=0:0.5
%]({0.5}, {x}, {0});
%\addplot3[dotted, samples y=1,
%    samples=2, domain=0:0.5
%]({x}, {x}, {0});


\nextgroupplot[unbounded coords=jump,clip=false, variable=x,
        variable y=y,zmax=0.25]

\addplot3[patch,patch type=triangle,color=gray,faceted color=gray,fill opacity=0.1] coordinates {(0,0,0) (1,0,0) (0,1,0)};
\addplot3[opacity=0.7,
     samples=20, samples y=20,
     domain=0:0.5, domain y=0:1,
     colormap/blackwhite, shader=interp, surf, z buffer=sort
 ] ({x},{upper(x,y)},{x*x}); 
\addplot3[opacity=0.7,
     samples=20, samples y=20,
     domain=0:0.5, domain y=0:0.5,
     colormap/blackwhite, shader=interp, surf, z buffer=sort
 ] ({lowerl(x,y)},{y}, {y*x} );
\addplot3[opacity=0.7,
     samples=20, samples y=20,
     domain=0.5:1, domain y=0:0.5,
     colormap/blackwhite, shader=interp, surf, z buffer=sort
 ] ({lowerr(x,y)}, {y}, {y*x} );
%%% lines
%\addplot3[dashed, samples y=1,
%    samples=2, domain=0:1
%]({0.5}, {0.5}, {x/2});
%\addplot3[gray, samples y=1,
%    samples=101, domain=0:0.5
%]({x}, {x}, {x});
%\addplot3[gray, samples y=1,
%    samples=2, domain=0:0.5
%]({0.5}, {x}, {x});
%\addplot3[dotted, samples y=1,
%    samples=2, domain=0:0.5
%]({0.5}, {x}, {0});
%\addplot3[dotted, samples y=1,
%    samples=2, domain=0:0.5
%]({x}, {x}, {0});


\end{groupplot}

    \end{tikzpicture}
\end{document}

I tried different sampling rates but it doesn't improve. Is there an issue with my parametric mappings or is it just pgfplots that is unable to make these plots?

2
+50

There are a couple of changes I'd suggest here.

  1. You only need one parametrization function (the three you have are the same). This is not a problem, of course.
  2. You need just two triangles for the domain of the parametrization. Not a problem either.
  3. The real problem (I think) is mixing the original coordinates x,y with the parameters (which I going to call u,v). This is confusing and causes problems as x,y need different domains too (with this parametrization). This is the problem in your third plot, but not in the first or the second because there are symmetry in those two.

In my example I plotted only the domain (two) triangles in the first plot. The rest are your plots reducing the samples and changing surf to mesh to better visualize what's happening.

\documentclass[border={10pt 10pt 10pt 10pt}]{standalone}
\usepackage    {pgfplots}
\pgfplotsset   {compat=1.17}
\usetikzlibrary{pgfplots.groupplots}

\begin{document}
\begin{tikzpicture}[declare function={param(\x,\y) = \x + \y*(1-2*\x);}]
\begin{groupplot}[
    group style={group size=2 by 2},
    xmin=0,xmax=1,
    ymin=0,ymax=1,
    view={-30}{65},
    axis line style={draw=none},
    tick style={draw=none},
    ticks=none,
    ]

% only the domain triangles (parametrized)
\nextgroupplot[unbounded coords=jump,clip=false,zmax=0.1]
\addplot3[opacity=0.7, variable=u, variable y=v,
     samples=11, samples y=11,
     domain=0:0.5, domain y=0:1,
     colormap/blackwhite, shader=interp, mesh, z buffer=sort
 ] (u,{param(u,v)},0); 
\addplot3[opacity=0.7, variable=u, variable y=v,
     samples=11, samples y=11,
     domain=0:1, domain y=0:0.5,
     colormap/blackwhite, shader=interp, mesh, z buffer=sort
 ] ({param(u,v)},v,0);

% first plot
\nextgroupplot[unbounded coords=jump,clip=false]
\addplot3[patch,patch type=triangle,color=gray,faceted color=gray,fill opacity=0.1] coordinates {(0,0,0) (1,0,0) (0,1,0)};
\addplot3[opacity=0.7, variable=u, variable y=v,
     samples=11, samples y=11,
     domain=0:0.5, domain y=0:1,
     colormap/blackwhite, shader=interp, mesh, z buffer=sort
 ] (u,{param(u,v)},u); 
\addplot3[opacity=0.7, variable=u, variable y=v,
     samples=11, samples y=11,
     domain=0:1, domain y=0:0.5,
     colormap/blackwhite, shader=interp, mesh, z buffer=sort
 ] ({param(u,v)},v,v);

% second plot
\nextgroupplot[unbounded coords=jump,clip=false]
\addplot3[patch,patch type=triangle,color=gray,faceted color=gray,fill opacity=0.1] coordinates {(0,0,0) (1,0,0) (0,1,0)};
\addplot3[opacity=0.7, variable=u, variable y=v,
     samples=11, samples y=11,
     domain=0:0.5, domain y=0:1,
     colormap/blackwhite, shader=interp, mesh, z buffer=sort
 ] (u,{param(u,v)},{u*(1-u-param(u,v))}); 
\addplot3[opacity=0.7, variable=u, variable y=v,
     samples=11, samples y=11,
     domain=0:1, domain y=0:0.5,
     colormap/blackwhite, shader=interp, mesh, z buffer=sort
 ] ({param(u,v)},v,{v*(1-param(u,v)-v)});

% third plot
\nextgroupplot[unbounded coords=jump,clip=false]
\addplot3[patch,patch type=triangle,color=gray,faceted color=gray,fill opacity=0.1] coordinates {(0,0,0) (1,0,0) (0,1,0)};
\addplot3[opacity=0.7, variable=u, variable y=v,
     samples=11, samples y=11,
     domain=0:0.5, domain y=0:1,
     colormap/blackwhite, shader=interp, mesh, z buffer=sort
 ] (u,{param(u,v)},{u*u}); 
\addplot3[opacity=0.7, variable=u, variable y=v,
     samples=11, samples y=11,
     domain=0:1, domain y=0:0.5,
     colormap/blackwhite, shader=interp, mesh, z buffer=sort
 ] ({param(u,v)},v,{v*param(u,v)});
\end{groupplot}
\end{tikzpicture}
\end{document}

enter image description here

Or, with surf instead of mesh: enter image description here

2
  • Thanks for your answer. For the second figure, the value of the function should be 0 at (0.5,0.5) because of the multiplication with `1-v-u). Why it doesn't look that way? Is this a scaling issue?
    – aaragon
    Jul 25 at 11:08
  • 1
    @aaragon, you are right. I made the same mistake in the second plot, confusing the x,y variables with the parameters u,v. I made an edit and I think it's corrected now. I failed too see but the, second plot should never take negative values and as you comment it must take value 0 at (0.5,0.5). You can see it better in the mesh. Jul 25 at 12:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.