2

This question is a follow-up to my last question. It concerns the problem of naming paths in such a way as to be able to perform operations on them such as

  1. translating or rotating them
  2. calculating intersections

Why is it that the following code produces an error no shape pathone is known

\documentclass[border=10mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\path [name path = pathone]     (0,0) -- ++ (2,2) ;
\draw [ultra thick] (pathone) ;
\end{tikzpicture}
\end{document}

while this works, calculates intersections but doesn't allow for shifting pathone

\documentclass[border=10mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\draw [name path = pathone, ultra thick]     (0,0) -- ++ (2,2) ;
\draw [name path = pathtwo, ultra thick]     (0,0) ++ (-0.4,0) -- ++ (2.4,2.4) ;
\draw [name path = pathtre, ultra thick]     (0,0) arc (180:90:2) ;
\draw [name intersections={of=pathtwo and pathtre, by={a, b}}]
      (a) circle (2pt)
      (b) circle (4pt) ;
% \draw [shift={(1,0)}] (pathone) ;
\end{tikzpicture}
\end{document}

while this code allows one to shift, but no intersections ...

\documentclass[border=10mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\def \pathone {(0,0) -- ++ (2,2)}
\def \pathtwo {(0,0) ++ (-0.4,0) -- ++ (2.4,2.4)}
\def \pathtre {(0,0) arc (180:90:2)}
\draw [ultra thick] \pathone ;
\draw [ultra thick] \pathtwo ;
\draw [ultra thick] \pathtre ;
% \draw [name intersections={of=\pathtwo and \pathtre, by={a, b}}]
%       (a) circle (2pt)
%       (b) circle (4pt) ;
\draw [ultra thick, shift={(1,0)}] \pathone ;
\end{tikzpicture}
\end{document}

and this code does everything :

\begin{tikzpicture}
\def \pathone {(0,0) -- ++ (2,2)}
\def \pathtwo {(0,0) ++ (-0.4,0) -- ++ (2.4,2.4)}
\def \pathtre {(0,0) arc (180:90:2)}
\draw [ultra thick] \pathone ;
\draw [ultra thick, name path = pathtwo] \pathtwo ;
\draw [ultra thick, name path = pathtre] \pathtre ;
\draw [name intersections={of=pathtwo and pathtre, by={a, b}}]
        (a) circle (2pt)
        (b) circle (4pt);
\draw [ultra thick, shift={(1,0)}] \pathone ;
\end{tikzpicture}

  1. What does\path [name path = mypath] ... ; do ?
  2. What kind of object is mypath (presumably it is a path) ?
  3. How do I summon mypath later on, and perform operations on it ?
  4. Why can't I draw the path mypath later, yet can use mypath to calculate intersections ?
  5. When should I use \def \mypath { ... } ?
  6. Is \mypath even a path ?
  7. Why is it I can manipulate \mypath (such as shifting it) but seemingly can't intersect it with some other path ?

In the end I'm interested in the question

What is the best way to define a path and giving it a name if I want to be able to use a given path later, possibly move it around etc ... ?

  • 1
    There are three layers: Top = TikZ = \path(0,0)--(10pt,10pt);; Middle = PGF = \pgfpathmoveto{\pgfpointorigin}\pgfpathlineto{\pgfpoint{10pt}{10pt}}; Bottom = PGFsys = \pgfsyssoftpath@moveto{0pt}{0pt}\pgfsyssoftpath@lineto{10pt}{10pt}. The transformation (including shifting) happens between middle and bottom. name path and intersecting paths happen at bottom. \def is purely top. – Symbol 1 May 19 '17 at 15:21
  • 1
    1. it stores the softpath tokens (\pgfsyssoftpath@xxxxxx) in to a macro called \tikz@intersect@path@name@mypath. 2. it is a sequence of softpath tokens. 3. you can only apply softpath operations. For example rounded corners and intersections happen at this level. 4. in fact you can. 5. when you know what you are doing. 6. sort of. It is a softpath. 7 a TikZ path should be translated into a softpath before calculating intersection. – Symbol 1 May 19 '17 at 15:29

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.