Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Is there a way to draw a TikZ path reversed?

I am trying to create some code that generates tessellating figures (to be used in How do we Draw a Bird in LaTeX).

Here is what I got:

\documentclass{minimal}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\def\x{2}
\def\y{4}
\def\mypath{(0,0) -- (1,1) -- (\x,0) -- (\x,\y)}
\draw \mypath;
\draw[shift={(\x,\y)}, rotate=180, blue] \mypath;
\end{tikzpicture}
\end{document}

It generates this: wrong But what I wanted is this:ok. So it is obviously not correct to rotate the path. I need to break it into two an draw it reversed.

share|improve this question
    
If you just put the URL of a question in your post, it'll be converted to the question title automatically, as can be seen in my edit. –  doncherry Mar 17 '12 at 22:55
    
The shape is already defined in the shape library with the name signal. Check the manual page 439. –  percusse Mar 17 '12 at 23:43
    
@percusse: I am trying to generate tessellating figures. I do not want to draw this specific shape. –  Hans-Peter E. Kristiansen Mar 17 '12 at 23:58
    
I don't see how "drawing it reversed" (whatever that actually means) gives you the result you want. You seem to want to get a path that is reflected in x everywhere, and reflected in y half of the time. Perhaps you should draw a different part of the path and reflect that (since you want the reflection over the x axis everywhere, I suggest drawing either the left or right hand side and mirroring that). Perhaps I am just misunderstanding you, it's not terribly clear. –  Roelof Spijker Mar 18 '12 at 0:35
    
Yes, but they are not symmetric (a slight smell of group theory, yuck!). In other words they don't fit together to form a shape that you want. –  percusse Mar 18 '12 at 0:43

2 Answers 2

up vote 5 down vote accepted

It's not possible with the definition of \mypath

enter image description here

\documentclass{minimal}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
  \def\x{2}
  \def\y{4}
  \def\mypath{(0,0) -- (1,1) -- (\x,0) -- (\x,\y)}
  \draw[red] \mypath;
\end{tikzpicture}
\hspace{1cm}
\begin{tikzpicture}
  \def\x{2}
  \def\y{4}
  \def\mypath{(0,0) -- (1,1) -- (\x,0) -- (\x,\y)}
  \draw[rotate=180, blue] \mypath;
\end{tikzpicture}
\end{document}

There is no shift possible to complete correctly your shape

but with

\documentclass{minimal}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
  \def\x{2}
  \def\y{4}
  \def\mypath{((1,1) -- (\x,0) -- (\x,\y)--++(-1,1)}
  \draw[red] \mypath;
  \draw[blue,x=-0.5*\x cm,xshift=\x cm]  \mypath; 
\end{tikzpicture}

\end{document}  

enter image description here

share|improve this answer

A solution to what you are trying to attempt is as follows :

  1. draw path forward
  2. shift
  3. draw path backwards
  4. close path

To make this easier, don't specify the path by actual points, but rather by displacements. The code is

\documentclass[border=5pt]{standalone}

\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}

\coordinate (start) at (0,0);
\def\shape{{(1,1)},{(1,-1)}}
\coordinate (shift) at (0,4);

\foreach \point [count=\n] in \shape {
        \node[coordinate] (d-\n) at \point {};
        }
\pgfmathtruncatemacro{\size}{\n}

\draw (start) 
      \foreach \i in {1,...,\size} {-- ++(d-\i)} %draw forward
      -- ++(shift) %shift
      \foreach \i in {\size,...,1} {-- ++($-1*(d-\i)$)} % draw backward
      -- cycle; %close


\end{tikzpicture}
\end{document}

The result is

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.