2

Following MWE draws a closed polygon.

 \documentclass{report}
 \usepackage{tikz}
 \begin{document}
 \begin{tikzpicture
 \draw (0,0) -- (0,1) -- (0.5, 1.5) -- (1,1) -- (1,0) -- cycle;
 \end{tikzpicture}
 \end{document}

How can I produce a second polygon whose edges are a given distance from the edges of a given polygon? The sketched result looks like this:

enter image description here

Karlo
  • 3,257
  • 4
    You can made a pic, and put that pic with different scale options at the same point – Black Mild May 17 '22 at 09:27
  • @BlackMild Yes, that would be a quick fix, but assume that you want to specify the distance between the two versions of the polygon. – Karlo May 17 '22 at 10:33
  • 1
    You can use polar coordinates and control the radius. – Sigur May 17 '22 at 10:55
  • Using scale(or equivalently scaled polar coordinates) will not give lines the same distance away all around for all figures(including this one). Here is a solution that only works with open paths: https://tex.stackexchange.com/questions/102975/draw-additional-parallel-paths-in-tikz – hpekristiansen Jun 16 '22 at 21:57

1 Answers1

2

If you really need a constant distance, it does not work to scale the figure, but you can use the solution given here: https://tex.stackexchange.com/a/103088/8650

The solution only works on open paths, so I close the path on one side like this:

\documentclass[tikz, border=1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations}
\def\pgfdecoratedcontourdistance{0pt}
\pgfkeys{/pgf/decoration/contour distance/.code={%
    \pgfmathparse{#1}%
    \let\pgfdecoratedcontourdistance=\pgfmathresult}%
}
\pgfdeclaredecoration{contour lineto}{start}
{
    \state{start}[next state=draw, width=0pt]{
        \pgfpathmoveto{\pgfpoint{0pt}{\pgfdecoratedcontourdistance}}%
    }
    \state{draw}[next state=draw, width=\pgfdecoratedinputsegmentlength]{       
        \pgfmathparse{-\pgfdecoratedcontourdistance*cot(-\pgfdecoratedangletonextinputsegment/2+90)}%
        \let\shorten=\pgfmathresult%
        \pgfpathlineto{\pgfpoint{\pgfdecoratedinputsegmentlength+\shorten}{\pgfdecoratedcontourdistance}}%  
    }
    \state{final}{
        \pgfpathlineto{\pgfpoint{\pgfdecoratedinputsegmentlength}{\pgfdecoratedcontourdistance}}%
    }   
}

\begin{document} \begin{tikzpicture} \draw [postaction={decoration={contour lineto, contour distance=-4pt}, draw, densely dashed, decorate}] (0,0.5) -- (0,1) -- (0.5, 1.5) -- (1,1) -- (1,0) -- (0,0) --cycle ; \end{tikzpicture} \end{document}

House shape with extra dashed line inside

To show that the shape is not just scaled, here is the same figure with a larger distance:

House shape with extra dashed line

It is seen that the inner shape is not the same as the outer shape.