1

I am working on a 3d figure using pgfplots. Since I need to operate on some pre-defined functions which are y(x) = - 1 - x and zed(x,y) = - x^2 - y^2.

I want to place points using these functions so I define the variables \xA=0, \yA=y(\xA) and \zA=zed(\xA,yA). The logical result is that the coordinates are (0,-1,-1). However, the result that I am getting is (0,-1,1), which is obviously wrong. For some reason, the "z" value is being returned with the opposite sign.

I have even tried loading the tikz math package but the result is the same...

Here is the MWE

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat = newest}
\usetikzlibrary{math}
\begin{document}
\begin{tikzpicture}[
    declare function={
    y(\x) = {-1 - \x };
    zed(\x,\y) = {-\x^2 - \y^2};
    }
    ]
\begin{axis}
\addplot3[surf,domain=-1:1,y domain=-1:1, 
] {zed(x,y)};

\tikzmath{ \x1 = 0; \y1 = y(\x1); \z1 = zed(\x1,\y1); }

\pgfmathsetmacro\xA{0} \pgfmathsetmacro\yA{y(0)} \pgfmathsetmacro\zA{zed(\xA,\yA)}

\node at (\xA,\yA,\zA) {(\xA,\yA,\zA)}; \node at (\x1,\y1,\z1) {(\x1,\y1,\z1)};

\end{axis} \end{tikzpicture}

\end{document}

which gives the following figure

enter image description here

What am I doing wrong?

Meclassic
  • 1,795
  • 2
  • 18
  • 27
  • 2
    zed(\x,\y) = {-(\x)^2 - (\y)^2} (there is a duplicate somewhere. Unary - and exponentiation have strange precedences in some part of the expressions...) – Rmano Feb 15 '24 at 16:14
  • @Rmano What do you mean by "unary -"? If you mean -1*\x^2-1*\y^2, the result is the same if I apply -0.2*\x^2-0.3*\y^2 for example. – Meclassic Feb 15 '24 at 16:18
  • @Rmano Ok, I just got it that the comment was the answer... Thanks. However, it would indeed be interesting to know where is the original duplicate to get more insight. I could not find any information about this issue. – Meclassic Feb 15 '24 at 16:20
  • I am not sure of the internals, but when for example \x is -1, what TeX sees of -\x^2 is - -1 ^2. Which if interpreted - (-1)^2 gives a value, otherwise if interpreted as -(-(1^2)) gives other. I suspect that the interpretation is not uniform in various part of the code... – Rmano Feb 15 '24 at 16:21
  • @Rmano Thanks for the insight. If no duplicate is found by other members, then you could post your comments as an answer. – Meclassic Feb 15 '24 at 16:23
  • Here: https://tex.stackexchange.com/a/125896/38080 – Rmano Feb 15 '24 at 16:23
  • @Rmano That does it. – Meclassic Feb 15 '24 at 16:25

0 Answers0