3

Using tikz I would like to add a local coordinate frame to a figure (the plane jpeg). If I place the plane in the origin (0,0) it seems to work fine with the following code.

\documentclass[preview, convert]{standalone}

\usepackage{tikz}

\begin{document}

\usetikzlibrary{arrows}
\begin{tikzpicture}[
    scale=1, 
    axis/.style={very thick, ->, >=stealth'}]

\draw[help lines] (0,0) grid (5,5);

\node[anchor=center,rotate=45,opacity=0.5] 
    (ego) at (0,0) {\includegraphics[scale=0.2]{latex/plane.jpeg}};
\begin{scope}[x={(ego.east)},y={(ego.north)}]
    \draw [<->, thick] 
        (-0.5,1.5) node [left] (y_ego) {$y$} -- 
        (-0.5,0) -- 
        (1.5,0) node [below right] (x_ego) {$x$};
\end{scope}

\end{tikzpicture}
\end{document}

enter image description here

But when I move it to another place (3,3 in this case) the local frame does not get moved as I expected. What am I doing wrong?

enter image description here

How can I attach a local coordinate frame to a figure?

1
  • Welcome to TeX.SE! Please, complete your code snipped to complete small document beginning with \documentclass{...} and with \end {document} on the end.
    – Zarko
    Mar 24, 2017 at 16:33

1 Answer 1

4

What about this:

  • Use default axis for the scope
  • Rotate the scope with the same angle as the figure

To easily show that I wrapped your figure in a macro: \myfig that takes the two parameters to show the behavior. Then, I just shift the scope and rotate it using the same amount.

\documentclass[preview, convert]{standalone}

\usepackage{tikz}

\begin{document}
  \usetikzlibrary{arrows}

  \newcommand{\myfig}[3]{
    \node[anchor=center,rotate=#3,opacity=0.5] 
    (ego) at (#1,#2) {\includegraphics[scale=0.2]{example-image-a}};

    \begin{scope}[shift=(ego.center), rotate=#3]
      \draw [<->, thick] 
      (0,1.5) node [left] (y_ego) {$y$} -- 
      (0,0) -- 
      (1.5,0) node [below right] (x_ego) {$x$};
    \end{scope}
  }

  \begin{tikzpicture}[
    scale=1, 
    axis/.style={very thick, ->, >=stealth'}
  ]
    \draw[help lines] (0,0) grid (5,5);

    \myfig{0}{0}{45}

    \myfig{3}{3}{45}

    \myfig{5}{0}{30}
  \end{tikzpicture}
\end{document}

enter image description here

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .