I'm playing around with intersections to draw an illustration for a lecture about optics. However, I'm having a few issues as the following example shows:
%!TEX encoding = UTF-8 Unicode
%!TEX program = lualatex
\documentclass[11pt,a4paper,fleqn,pdftex]{report}
\usepackage[dvipsnames, table]{xcolor}
\usepackage[utf8]{luainputenc}
\usepackage[latin,english]{babel}
\usepackage{tikz}
\usetikzlibrary{patterns}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{figure}[!h]
\centering
\begin{tikzpicture}
\coordinate (M2) at (0,3);
\def\angleM{10}
% >>>>>>>>>>>>>>>>
\draw[color=Red, thick] (M2) -- (intersection cs: first line={(M2)--++(90 - \angleM:-8)}, second line={(45:-4)--(45:4)}) circle (2pt);
\draw[color=Red, thick] (intersection cs: first line={(M2)--++(90 - \angleM:-8)}, second line={(45:-4)--(45:4)}) circle (2pt) -- (M2);
% <<<<<<<<<<<<<<<<
\draw[thick] (M2) ++(1,0) -- ++(-2,0) node[left]{$M_2$};
\fill[pattern=north east lines] (M2) ++(1,0) rectangle ++(-2,0.2);
\draw[very thick] (45:-2) -- (45:2);
\end{tikzpicture}
\end{figure}
\end{document}
In this example, the two lines between % >>>>>… and % <<<<… should draw the same lines, but don't as you can see here:

While the instructions are almost the same (only the draw direction differs), the lines don't overlap as they should. What can I do to avoid this?

intersectionslibrary\usetikzlibrary{intersections}and then do\path[name path=line1] (M2)--++(90 - \angleM:-8) [name path=line2] (45:-4)--(45:4); \draw[Red,thick,name intersections={of=line1 and line2}] (intersection-1) -- (M2);it's a bit longer than using theintersection cs, but you won't be depending on rounding problems. – Gonzalo Medina Feb 21 '15 at 21:33backgroundlibrary exactly for this. Have a look at the PGF manual, Section 109 Layered Graphics. – Gonzalo Medina Feb 21 '15 at 23:28