3

Is it possible to define a TikZ style that shifts a path perpendicularly? I.e., the resulting path should be obtained from the given path by shifting every point, say, 0.1cm to the right, orthogonal to the direction of the path at this point.

This should work for arbitrary paths (not just straight lines). Also, I do not just want to draw a line along the shifted path, but also do clipping or filling, etc. So using the "raise=..." key together with a decoration as described in "perpendicular shift" for paths won't work I think.

  • it would be helpful to have a handrawn sketch of the desired result – js bibra Jul 16 '20 at 14:14
  • maybe a clearer definition of what I want: Draw a line with line width=0.2cm along the original path. The desired path is the right boundary of that line. – Andi Bauer Jul 16 '20 at 14:27
  • So the intended use I have in mind is to draw the boundary of some shape (like a rectangle, circle, etc.) and at the same time clip to the "white part inside the shape" which is distinct from the drawn path because the line has a finite width. – Andi Bauer Jul 16 '20 at 14:30
  • Is there really no simple way in TikZ to stroke a closed path and at the same time clip to the inside edge of the stroked line (instead of the center line of the stroked line)? – Andi Bauer Jul 16 '20 at 15:26
  • I have written here a macro (but not a tikz style) that moves the start and end point of a path perpendicularly and then all the others. Annotating a table with arrows – AndréC Jul 16 '20 at 17:08
  • 1
    The answers to this question actually define a path that is parallel to the main path, and therefore corresponds to your request. Flexure of a Grid – AndréC Jul 16 '20 at 20:17
  • 1
    Thanks for that link! The second answer therein looks like what I want, however, it just draws many strokes on top of each other, and wouldn't give me the chance to use the "inner edge" of the grid for, e.g., clipping... – Andi Bauer Jul 16 '20 at 20:45
  • I was not notified of your response to my comments. When more than one person has written comments, it is necessary to indicate who you are writing to so that they can be notified. Read more: How do comment @replies work? – AndréC Jul 17 '20 at 05:50

2 Answers2

3

Some examples from page 151 of the pgf book maybe point in the right direction

enter image description here

enter image description here

enter image description here

\documentclass{article}

\usepackage{tikz} \usetikzlibrary{calc} \begin{document}

\begin{tikzpicture} \draw [help lines] (0,0) grid (3,2); \coordinate (a) at (1,0); \coordinate (b) at (3,1); \draw (a) -- (b); \coordinate (c) at ($ (a)!.25!(b) $); \coordinate (d) at ($ (c)!1cm!90:(b) $); \draw [<->] (c) -- (d) node [sloped,midway,above] {1cm}; \end{tikzpicture} \begin{tikzpicture} \draw [help lines] (0,0) grid (3,2); \coordinate (a) at (0,1); \coordinate (b) at (3,2); \coordinate (c) at (2.5,0); \draw (a) -- (b) -- (c) -- cycle; \draw[red] (a) -- ($(b)!(a)!(c)$); \draw[orange] (b) -- ($(a)!(b)!(c)$); \draw[blue] (c) -- ($(a)!(c)!(b)$); \end{tikzpicture} \end{document}

js bibra
  • 21,280
3

If I understood your question correctly, this is natively possible with TikZ's double option which allows you to draw a double line. Here is a slightly modified example from the Graphic Parameters: Double Lines and Bordered Lines section of the 3.1.5b manual.

screenshot

\documentclass[tikz,border=5mm]{standalone}

\begin{document} \begin{tikzpicture} \draw[very thick,double] (0,0) arc (180:90:1cm); \draw[very thick,double distance=5pt,double=green!50] (1,0) arc (180:90:1cm); \draw[thin,double distance=.1cm] (2,0) arc (180:90:1cm); \end{tikzpicture}

\end{document}

AndréC
  • 24,137