In a recent tutorial style answer for How can I draw these polygons with shaded regions?, I encountered some strange behavior with tikz. The code below is a slightly reduced version of the code from that answer. I attempted to reduce it even further, but that made the issue harder to see.
Here is what I get if I end the line below in black with -- cycle:
\draw (A1) -- (intersection-1) -- (A4) -- cycle;

Notice how the black lines go past the points at A1 and A4.
But, by not using -- cycle and instead re-specifying the starting point as the ending point, I get better results for the A1:
\draw (A1) -- (intersection-1) -- (A4) -- (A1);

A way to fix this is below, but why is the behavior different if using --cycle or re-specifying the starting point as the end point?
References:
- Based on How to fix TikZ corners in 3D, applying
line join=rounddoes fix this and yields the desired results:

Code:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
% Define all the points:
\coordinate (A1) at (0,4);
\coordinate (A2) at (3,6);
\coordinate (A3) at (5,5);
\coordinate (A4) at (6,3);
\coordinate (A5) at (4.5,1.5);
\coordinate (An) at (0,0);
% Draw the lines
\draw [ultra thick, blue, solid ] (An) -- (A1) -- (A2) -- (A3) -- (A4) -- (A5);
% Label the nodes:
\foreach \Index/\Position in {1/left, 2/above, 3/above right, 4/right, 5/below right, n/left} {
\node [\Position] at (A\Index) {$A_{\Index}$};
}%
\draw [gray, ultra thick]
[name path=A1A3] (A1) -- (A3)
[name path=A2A4] (A2) -- (A4)
[name path=A1A4] (A1) -- (A4);
\fill [fill=red!20, draw=black, ultra thick, name intersections={of=A1A3 and A2A4}]
(A1) -- (intersection-1) -- (A4) -- cycle;% produces wacky vertices
%(A1) -- (intersection-1) -- (A4) -- (A1);% this fixes problem at (A)
% % Following fix works
% \fill [fill=red!20, draw=black, line join=round, ultra thick, name intersections={of=A1A3 and A2A4}]
% (A1) -- (intersection-1) -- (A4) -- cycle;
\end{tikzpicture}
\end{document}
