# Tikz: Fill the intersection between two polygons

I'm trying to fill the intersection of the two polygons that I have made using tikz. But it seems like I have some mistake in my \clip and \fill commands that I can't get what I want. This is what I want actually:

Here's the TeX script that I wrote for that purpose:

\documentclass[english]{scrreprt}
\usepackage{tikz}
\usetikzlibrary{shapes,calc,intersections}

\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[scale=2.5]

\node    [draw, regular polygon,regular polygon sides=5,rotate=85,scale=8., name = A] at (0.3,0) {};
\node    [draw, regular polygon,regular polygon sides=7,rotate=80,scale=10, name = B] at (1.4,0) {};

\begin{scope}
\clip (0.3,0)    [regular polygon,regular polygon sides=5,rotate=85,scale=8.];
\fill [orange]   (1.4,0) [regular polygon,regular polygon sides=7,rotate=80,scale=10];
\end{scope}

\end{tikzpicture}
\end{figure}
\end{document}


As you can see I need the coordinates of the centroids of the two polygons, otherwise I would have used simply the \draw command to draw them.

Thanks a ton!

I can explain why your code for filling the intersection doesn't work. You're using a node as clipping path and a node is not a path, as soon as you could declare a real path for clipping, the intersection will be filled.

Next command defines a closed path around regular polygon corners

\clip (A.corner 1) foreach \i in {2,3,4,5} {--(A.corner \i)} --cycle;


which can be used to clip a reproduction of second polygon

\node[fill=orange, regular polygon,regular polygon sides=7,rotate=80,scale=10] at (1.4,0) {};


Note that also outer sep=0pt has been added in first regular polygon because otherwise scale option moves corner anchors. I don't know why (probably related with this Note 1).

\documentclass[border=2mm,tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,calc,intersections}

\begin{document}
\begin{tikzpicture}[scale=2.5]

\node[draw, shape=regular polygon,regular polygon sides=5,rotate=85,scale=8., name = A, outer sep=0pt] at (0.3,0) {};
\node[draw, regular polygon,regular polygon sides=7,rotate=80,scale=10, name = B] at (1.4,0) {};

\begin{scope}
\clip (A.corner 1) foreach \i in {2,3,4,5} {--(A.corner \i)} --cycle;
\node[fill=orange, regular polygon,regular polygon sides=7,rotate=80,scale=10] at (1.4,0) {};
\end{scope}

\end{tikzpicture}
\end{document}


• Thanks for the reply. I just get an error about missing semicolon at the line \clip (A.corner 1)... Could there be something missing there? Sorry I'm not that expert with clipping to find it out on my own... – Dan Pourjafar Feb 12 '15 at 13:49
• @DanPourjafar There's nothing wrong with the code (overleaf.com/2241422ybddct). It works with TiKZ 3.0. May be you are using an earlier version. Or you forgot to copy some semicolon somewhere ;-) – Ignasi Feb 12 '15 at 14:51
• You're right I was using the 2.10 version. I guess that's the problem. Any ways thanks a lot for your help! – Dan Pourjafar Feb 12 '15 at 15:23