3

I am trying to plot two vector fields (x,y) and (-y,x) on a manifold where the norm is given by $x^2 - y^2$ instead of $x^2 + y^2$. Furthermore, I want the vector fields to be only plotted if x>y. Below is my attempt:

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}

\def\rescale{
       0.5*(sign(x^2-y^2)+1)*sqrt(x^2-y^2)/sqrt(x^2+y^2)
}

\begin{tikzpicture}
\begin{axis}[
    xmin = 0, ymax = 5,
    ymin = -5, ymax = 5,
    view={0}{90}
]
\draw [black] (0,0) -- (5,5);
\draw [black] (0,0) -- (5,-5);
\clip  (0.0, 0) -- (4.80, 4.80) -- (4.80, -4.80) -- cycle;
\addplot3[blue, quiver={u={x*\rescale}, v={y*\rescale}, scale arrows=0.15}, -stealth,samples=20] {0};
\addplot3[red,  quiver={u={y*\rescale}, v={x*\rescale}, scale arrows=0.15}, -stealth,samples=20] {0};
\end{axis}
\end{tikzpicture}
\end{document}

The problem is that the vectors from the xy region. I included the figure to clarify:enter image description here

The vector arrows near the black triangular lines are actually plotted vectors from outside the desired region !

  • Mathjax is not available here :) and what do you mean by various "error"? Be specific, if possible add them to your question to give a better clarity. – Raaja May 24 '17 at 9:22
  • @RaajaG, I included the errors but I don't think that they are very helpful. I think that the \ifthenelse statement is not compatible with some other processes but I have no clue why. (but if is change that line into 1 I get zero errors) – gertian May 24 '17 at 9:24
  • What errors? What \ifthenelse? Which black triangular lines? No idea what you are trying to do .... – cfr May 26 '17 at 2:14
  • @cfr I already adjusted my question since I was able to get rid of the errors myself. The current plot is quite close to what I would like to achieve but there are still some unwanted vectors being plotted from outside the "triangular" area. e.g. The small vectors that are pointing straight up should not be there ! – gertian May 26 '17 at 9:52
  • Presumably, they are parts of vectors, where part is inside the clipped area and part is outside. So either you need to not rely on clipping here or you need to adjust the area you clip to in order to eliminate parts of unwanted vectors which impinge on the area you want. But I still don't see any black triangles. I read the comments because I didn't understand the question really. – cfr May 26 '17 at 17:05

Your Answer

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

Browse other questions tagged or ask your own question.