# drawing a line at the intersection of polygons?

I have two intersecting polygon. Since I am filling and drawing the second polygon on top of it, the first polygon becomes hidden(at the overlapping areas). I want to show the the overlap of first polygon (the edges) with a dotted line over the second polygon. Should I find the intersections and make it as two nodes, then draw a path between them?

    \documentclass[crop,tikz]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=1]
\draw[fill=blue!30,draw,thick,shift={(-2.236,0 )},rotate =
-153.432368] (0,0)--(-1.5,2)--(-2,1)--(-2,-1)--(-1.5,-2)--(0,0)--
cycle;
\draw[fill=red!30,draw,thick,shift={(-2.236,0 )},rotate =
153.432368]
(0,0)--(-1.5,2)--(-2,1)--(-2,-1)--(-1.5,-2)--(0,0)--cycle;
\draw[latex-latex,thick] (-4,0)--(1,0) node[right]{$x$};
\draw[latex-latex,thick] (0,-3)--(0,3) node[above]{$y$};
\end{tikzpicture}
\end{document}


I want something like this. Thanks in advance.

If you just want a dotted line you can redraw the first polygon without fill.

\documentclass[crop,tikz]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=1]
\draw[fill=blue!30,draw,thick,shift={(-2.236,0 )},rotate =
-153.432368] (0,0)--(-1.5,2)--(-2,1)--(-2,-1)--(-1.5,-2)--(0,0)--
cycle;
\draw[fill=red!30,draw,thick,shift={(-2.236,0 )},rotate =
153.432368]
(0,0)--(-1.5,2)--(-2,1)--(-2,-1)--(-1.5,-2)--(0,0)--cycle;
\draw[dotted,shift={(-2.236,0 )},rotate = -153.432368] (0,0)--(-1.5,2)--(-2,1)--(-2,-1)--(-1.5,-2)--(0,0)-- cycle;
\draw[latex-latex,thick] (-4,0)--(1,0) node[right]{$x$};
\draw[latex-latex,thick] (0,-3)--(0,3) node[above]{$y$};
\end{tikzpicture}
\end{document}


If you want it more like in your picture, where overlap is marked with red dashed line, you can use a scope and clip.

\documentclass[crop,tikz]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=1]
\draw[fill=blue!30,draw,thick,shift={(-2.236,0 )},rotate =
-153.432368] (0,0)--(-1.5,2)--(-2,1)--(-2,-1)--(-1.5,-2)--(0,0)--
cycle;
\draw[fill=red!30,draw,thick,shift={(-2.236,0 )},rotate =
153.432368]
(0,0)--(-1.5,2)--(-2,1)--(-2,-1)--(-1.5,-2)--(0,0)--cycle;
\begin{scope}
\clip[shift={(-2.236,0 )},rotate = 153.432368] (0,0)--(-1.5,2)--(-2,1)--(-2,-1)--(-1.5,-2)--(0,0)--cycle;
\draw[color=red,dashed,shift={(-2.236,0 )},rotate = -153.432368] (0,0)--(-1.5,2)--(-2,1)--(-2,-1)--(-1.5,-2)--(0,0)-- cycle;
\end{scope}
\draw[latex-latex,thick] (-4,0)--(1,0) node[right]{$x$};
\draw[latex-latex,thick] (0,-3)--(0,3) node[above]{$y$};
\end{tikzpicture}
\end{document}


with use of intersections:

\documentclass[crop,tikz]{standalone}
\usetikzlibrary{intersections}

\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=1]
\draw[name path=A,
fill=blue!30,draw,thick,xshift=-2.236cm,rotate =-153.432368] (0,0)--(-1.5,2)--(-2,1)--(-2,-1)--(-1.5,-2)--(0,0)-- cycle;
\draw[name path=B,
fill=red!30,draw,thick,xshift=-2.236cm,rotate =153.432368]
(0,0)--(-1.5,2)--(-2,1)--(-2,-1)--(-1.5,-2)--(0,0)--cycle;
% intersections
\path[name intersections={of=A and B, name=i, total=\t}, dashed, draw=red]
%\foreach \s in {1,...,\t}{(i-\s) circle (2pt) node[above] {\footnotesize\s}}% for discover intersection names;
(i-1) -- (i-2)
(i-3) -- (i-4);
% axes
\draw[latex-latex,thick] (-4,0)--(1,0) node[right]{$x$};
\draw[latex-latex,thick] (0,-3)--(0,3) node[above]{$y$};
\end{tikzpicture}
\end{document}