Menu

#53 positioning and rotate nodes

Future
pending
nobody
None
5
2018-12-31
2010-08-04
No

Hello,

using the positioning library to place rotated nodes causes "unexpected" results (see the attached file for a minimal example). With the default option on grid=false cause positioning relative to rotated anchors and, in this example, the nodes are not vertically aligned.

It would be nice to have an absolute option for positioning, analogous to the option introduced for labels in the cvs version. That is let positioning use anchor on the borders whose angle is measured "absolutely", that is 0 is always above, etc...

Marco Pizzocaro

Discussion

  • Marco Pizzocaro

    Marco Pizzocaro - 2010-08-04

    minimal example of rotated nodes with positioning library

     
  • Marco Pizzocaro

    Marco Pizzocaro - 2010-08-17

    Despite my little knowledge of TeX programming, I worked out a solution.
    I hope I could discuss it here.

    I have called the option absolute angle positioning.
    When it is set to true, basically, it allows positioning of rotating nodes, keeping them aligned.
    The node distance is put between the anchor on the borders of the two shape along the line connecting the two centers.

    For positioning relative to rotated nodes, I copied and pasted the code for labels.

    Placing a rotated node is, instead, a formidable problem.
    I should compute the correct anchor on the border before creating the node.
    For example, using:

    \node (a) {A};
    \node[rotate=90, above=of a] (b) {B};
    

    then the b node should be invoked with the anchor set to 180, that is 270 (since I want it above) rotated by -90° (the inverse of the transformation applied to the node).
    In order to do so I should:
    - take the transformation applied to the node (learning how to do this take me a while...);
    - remove shifts;
    - inverte it;
    - use the inverted transfomation with a point in the correct direction (in the above example \pgfpointpolar{270}{1pt});
    - extract the polar angle coordinate from the cartesian coordinates of the transformed point;
    - use this angle to create the node.

    I have attached my modification of the library and an example.

    Two comments:

    1. the transformation commands should be given before the placing command:
    \node[rotate=90, above=of a] (b) {B};
    

    has a different result than

    \node[above=of a, rotate=90] (b) {B};
    

    since I cannot foresee the transfomation applied to a node.
    2. for the future, it would be nice to be able to avoid all the calculation explained above.
    For example allowing pgf/tikz to interpret angle for anchor on the border "absolutely" on their own.

    What do you think?

    Regards,
    Marco Pizzocaro

     

    Last edit: Stefan Pinnow 2018-12-31
  • Marco Pizzocaro

    Marco Pizzocaro - 2010-08-17

    a modification of the positioning library that can handle rotated nodes

     
  • Marco Pizzocaro

    Marco Pizzocaro - 2010-08-17

    an example of the modified positioning library in action

     
  • Till Tantau

    Till Tantau - 2013-09-30
    • status: open --> pending
    • Group: --> Future
     
  • Stefan Pinnow

    Stefan Pinnow - 2018-12-31

    Some of the above said stuff doesn't to be valid any more. Also I am not sure if the current result -- also with your modified code -- gives the result you/one would expect. Therefore here a modified version of your MWE with the corresponding result.

    \documentclass[border=2pt]{standalone}
    \usepackage{tikz}
        \usetikzlibrary{positioning2}
        \tikzset{
            every node/.style={
                rectangle,
                draw,
            },
        }
    \begin{document}
        \begin{tikzpicture}
            \node (a)  {a};
            \node (b)  [rotate=90, below=of a,] {b};
            \node (c)  [below=of b, ] {c};
    
            % in the mean time the order of the provided keys `rotate' and `below'
            % doesn't matter any more ...
            \node (b2) [red,dashed,below=of a,rotate=90] {b};
            % ... but `anchor' does
            \node (b3) [green,rotate=90, below=of a,anchor=east] {b};
            \node (b4) [blue,dotted,thick,anchor=east,rotate=90, below=of a,] {b};
        \end{tikzpicture}
    
        \begin{tikzpicture}[
            absolute angle positioning,
        ]
            \node (a)  {a};
            \node (b)  [rotate=90, below=of a,] {b};
            \node (c)  [below=of b, ] {c};
        \end{tikzpicture}
    \end{document}