11

I'm working on a picture using TikZ and I'm using intersections to draw some points (the $α(t_{j+i}$). I saw that the picture would fit better into the page if I rescaled it and rotated 90 degrees, and to my surprise this completely messes up the intersections. This is the output without rotations or scalings:

Normal picture

This is what happens when I scale the picture (the intersections are off their corresponding points, but not much):

Scaled picture

And this is what happens when I rotate it: completely messed up.

Rotated picture

It seems that TikZ is applying two times the transformation: scale to 0.64 instead of 0.8, or rotate by 180 degrees instead of just 90. Here's the MWE

\documentclass{minimal}

\usepackage{tikz}

\usetikzlibrary{arrows}
\usetikzlibrary{patterns}
\usetikzlibrary{intersections}
\begin{document}

\tikzstyle{nodepoint}=[inner sep=1pt, circle, draw, black, fill=black]

\begin{tikzpicture}[rotate = 0, scale=1]

\pgfmathsetmacro{\uiminoraxis}{3}
\pgfmathsetmacro{\uimajoraxis}{4}
\pgfmathsetmacro{\uilabelfactor}{1.2}
\pgfmathsetmacro{\uiinclination}{45}

\begin{scope}
\clip[rotate around={\uiinclination:(-\uimajoraxis,0)}] (0,0) ellipse ({\uimajoraxis} and {\uiminoraxis});
\fill[pattern=north east lines, pattern color=orange!80!white] (0,0) ellipse ({\uimajoraxis} and {\uiminoraxis});
\end{scope}

\foreach[count=\i] \a in {\uiinclination, 0, -\uiinclination}
{
    \begin{scope}[rotate around={\a:(-\uimajoraxis,0)}, scale=1]
        \draw[name path global=open\i] (0,0) ellipse ({\uimajoraxis} and {\uiminoraxis});
        \draw[dotted, name path global=axis\i] ({-\uimajoraxis},0) -- ({\uimajoraxis}, 0);
        \node at ({\uimajoraxis*\uilabelfactor}, 0) {$U_\i$};
    \end{scope}
}

\node[nodepoint, label={left:$x_0$}] (X) at (-\uimajoraxis / 2,0) {};

\draw[rotate around={\uiinclination:({-\uimajoraxis},0)}, (-), red] ({-\uimajoraxis / 2}, {1}) to[bend left] node[midway, above, sloped, yshift=4] {$A_j$} (1,1);

\draw[dotted, name path=outercircle] ({-\uimajoraxis},{1.44*\uimajoraxis}) arc[start angle = {\uiinclination*2}, end angle = {-\uiinclination * 2}, radius={1.44*\uimajoraxis}];

\draw[dotted, name path=joiner1, name intersections={of=open1 and open2}] (intersection-1)  -- (intersection-2);
\draw[dotted, name path=joiner2, name intersections={of=open2 and open3}] (intersection-1)  -- (intersection-2);

\node[name intersections={of=axis1 and outercircle}, nodepoint, label={above:{$\alpha(t_j)$}}] (AJ0) at (intersection-1) {};
\node[name intersections={of=axis2 and outercircle}] (AJ1) at (intersection-1) {};
\node[name intersections={of=axis3 and outercircle}, nodepoint, label={below:{$\alpha(t_{j+3})$}}] (AJ2) at (intersection-1) {};

\node[nodepoint, name intersections={of=joiner1 and outercircle}, label={right:{$\alpha(t_{j+1})$}}] (J1) at (intersection-1) {};
\node[nodepoint, name intersections={of=joiner2 and outercircle}, label={left:{$\alpha(t_{j+2})$}}] (J2) at (intersection-1) {};

\draw[blue, thick] (AJ0) to[bend left] node[midway, right] {$A_j$} (J1);
\draw[blue, thick] (J1) to[bend left] node[midway, right] {$A_{j+1}$} (J2);
\draw[blue, thick] (J2) to[bend left] node[midway, right] {$A_{j+2}$} (AJ2);

\draw[green!70!black, thick] (X) to[bend left] node[midway, above] {$\beta_j$} (J1);
\draw[green!70!black, thick] (J2) to[bend right] node[midway, below] {$\beta_{j_1}^-$} (X);
\end{tikzpicture}

\end{document}

Does anybody know what could be happening?

  • Please don't use minimal for examples as it is not intended for this purpose. – cfr Dec 16 '14 at 18:29
  • Do you want to rotate the whole thing, including the labels, so that the page needs turning to view it? Or do you want the labels not to be rotated? – cfr Dec 16 '14 at 18:33
  • @cfr, ok, what should I use? I enabled minimal so I coud check it's not my custom document class the one making weird things. And, btw, I want to keep the labels upright, rotating just the shapes (the usual TikZ rotation). – gjulianm Dec 16 '14 at 20:06
  • 1
    article is an obvious choice. standalone is another possibility. – cfr Dec 16 '14 at 20:42
6

There seems to be a bug in node at used with intersections.

Here is an example :

\documentclass[varwidth,border=50]{standalone}
\usepackage{tikz}

\usetikzlibrary{intersections}
\begin{document}

\tikzstyle{nodepoint}=[inner sep=1pt, circle, draw, black, fill=black]

\begin{tikzpicture}[rotate = 30, scale=1]
  \node[nodepoint]{};

  \draw[name path=a] (120:1) -- (10:1); 
  \draw[name path=b] (0:0) -- (90:1);

  \node[nodepoint, red, name intersections={of=a and b}] at (intersection-1) {};
  \path[name intersections={of=a and b}] (intersection-1) node[nodepoint, green] {};

\end{tikzpicture}

\end{document}

enter image description here

So by replacing \node at (point) with \path (point) node it shoud be ok.

EDIT: Here is the corrected code :

\documentclass{minimal}

\usepackage{tikz}

\usetikzlibrary{arrows}
\usetikzlibrary{patterns}
\usetikzlibrary{intersections}
\begin{document}

\tikzstyle{nodepoint}=[inner sep=1pt, circle, draw, black, fill=black]

\begin{tikzpicture}[rotate = 30, scale=.9]

\pgfmathsetmacro{\uiminoraxis}{3}
\pgfmathsetmacro{\uimajoraxis}{4}
\pgfmathsetmacro{\uilabelfactor}{1.2}
\pgfmathsetmacro{\uiinclination}{45}

\begin{scope}
\clip[rotate around={\uiinclination:(-\uimajoraxis,0)}] (0,0) ellipse ({\uimajoraxis} and {\uiminoraxis});
\fill[pattern=north east lines, pattern color=orange!80!white] (0,0) ellipse ({\uimajoraxis} and {\uiminoraxis});
\end{scope}

\foreach[count=\i] \a in {\uiinclination, 0, -\uiinclination}
{
    \begin{scope}[rotate around={\a:(-\uimajoraxis,0)}, scale=1]
        \draw[name path global=open\i] (0,0) ellipse ({\uimajoraxis} and {\uiminoraxis});
        \draw[dotted, name path global=axis\i] ({-\uimajoraxis},0) -- ({\uimajoraxis}, 0);
        \node at ({\uimajoraxis*\uilabelfactor}, 0) {$U_\i$};
    \end{scope}
}

\node[nodepoint, label={left:$x_0$}] (X) at (-\uimajoraxis / 2,0) {};

\draw[rotate around={\uiinclination:({-\uimajoraxis},0)}, (-), red] ({-\uimajoraxis / 2}, {1}) to[bend left] node[midway, above, sloped, yshift=4] {$A_j$} (1,1);

\draw[dotted, name path=outercircle] ({-\uimajoraxis},{1.44*\uimajoraxis}) arc[start angle = {\uiinclination*2}, end angle = {-\uiinclination * 2}, radius={1.44*\uimajoraxis}];

\draw[dotted, name path=joiner1, name intersections={of=open1 and open2}] (intersection-1)  -- (intersection-2);
\draw[dotted, name path=joiner2, name intersections={of=open2 and open3}] (intersection-1)  -- (intersection-2);

\path[name intersections={of=axis1 and outercircle}] (intersection-1) node[nodepoint, label={above:{$\alpha(t_j)$}}] (AJ0) {};
\path[name intersections={of=axis2 and outercircle}] (intersection-1) node (AJ1) {};
\path[name intersections={of=axis3 and outercircle}] (intersection-1) node[nodepoint, label={below:{$\alpha(t_{j+3})$}}] (AJ2) {};

\path[name intersections={of=joiner1 and outercircle}] (intersection-1) node[nodepoint, label={right:{$\alpha(t_{j+1})$}}] (J1) {};
\path[name intersections={of=joiner2 and outercircle}] (intersection-1) node[nodepoint, label={left:{$\alpha(t_{j+2})$}}] (J2) {};

\draw[blue, thick] (AJ0) to[bend left] node[midway, right] {$A_j$} (J1);
\draw[blue, thick] (J1) to[bend left] node[midway, right] {$A_{j+1}$} (J2);
\draw[blue, thick] (J2) to[bend left] node[midway, right] {$A_{j+2}$} (AJ2);

\draw[green!70!black, thick] (X) to[bend left] node[midway, above] {$\beta_j$} (J1);
\draw[green!70!black, thick] (J2) to[bend right] node[midway, below] {$\beta_{j_1}^-$} (X);
\end{tikzpicture}

\end{document}

enter image description here

  • (+1) I think you can't use name intersections as an option for a node. That makes a kind of sense to me, I think, since figuring out the intersections seems to be a path-type thing to do. If you name the intersections first, and then position the node, it works fine. E.g. \path[name intersections={of=a and b}] (intersection-1) node[nodepoint, green] {}; \node[nodepoint, red] at (intersection-1) {}; gets you a red circle over the top of the green one. – cfr Dec 16 '14 at 20:48
  • @cfr yes exactly what I say. If you use \path[...] (intersection-1) node it is ok. But why you said it is not a bug ? The transformation is applyed twice if intersection is used in \node at` : this looks like a bug for me. – Kpym Dec 16 '14 at 20:52
  • @cfr you can use named intersections inside nodes : the proof is the original picture without the transformation. Everything is ok in this case, nodes are placed exactly as expected. I think that this problem can have something with the fact that named coordinates outside of a scope are not transformed. And probably here is one more time a scope problem. – Kpym Dec 16 '14 at 21:02
  • I didn't mean it wasn't a bug (I don't know if it is or not). Just trying to pin-point the problem more specifically i.e. it is not using a named intersection point in an option to the node which creates the problem, but naming the intersection point in an option to the node. If the point is already named as part of a previous \path operation, using the named node as part of a \node operation doesn't cause issues. Sorry if I wasn't clear. – cfr Dec 16 '14 at 21:12
  • @cfr ok we agree ;) – Kpym Dec 16 '14 at 21:18

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.