TransWikia.com

plot a surface using a nonrectangular domain

TeX - LaTeX Asked on August 7, 2021

There is a way to plot a surface in a nonrectangular domain?
For example, plot f(x,y)=x^2+y^2 where 0 <= x <= 1$ and x^2 <= y <= x?
I have the following code, almost the result witha conditional structure.

documentclass[11pt,border=10mm]{standalone}
usepackage{pgfplots}

begin{document}

begin{tikzpicture}
begin{axis}[domain=0:1, y domain=0:1,samples=20,no marks]
addplot3[surf,gray,samples=30, samples y=30](x,y,0);
addplot3[surf,colormap/hot,samples=30, samples y=30](x,y,{(x < y && x> y^2?x^2+y^2:0)});
end{axis}
end{tikzpicture}

end{document}

The output is:
enter image description here

I would like, to disconsider the 0 value (out of my domain). In Gnuplot, it accept NaN if the point are out of the domain; but here no.

One Answer

A possible solution is to parametrize the domain, changing the variables so that the new domain is "rectangular". For instance, if we take y=x*t+x^2*(1-t) as in the following code:

documentclass{standalone}
usepackage   {pgfplots}
pgfplotsset  {compat=1.17}

begin{document}
begin{tikzpicture}
begin{axis}
[
  xlabel=$x$,
  ylabel=$y$,
  zmin=0,
  zmax=2,
  domain=0:1, y domain=0:1,
  samples=20, samples y=10,
  variable y=t,
  view={30}{45}
]
addplot3[mesh,gray]               (x, {x*t+x^2*(1-t)}, 0);
addplot3[surf, colormap name=hot] (x, {x*t+x^2*(1-t)}, {x^2+(x*t+x^2*(1-t))^2});  
end{axis}
end{tikzpicture}
end{document}

we can obtain this picture: enter image description here

Answered by Juan Castaño on August 7, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP