# Intersection with rays in TikZ

can anyone tell me how to calculate intersections of rays and objects in TikZ? Normally the syntax is intersection of p1--p2 and p3--p4, but I would like to intersect the line segment from p1 to p2 with a ray starting at p3 and going into a direction e. Is that possible with TikZ?

-
What is e in TikZ object terms? A coordinate that you're treating like a vector? –  Matthew Leingang Feb 18 '11 at 11:23
I think this should be a feature request! –  student Oct 31 '12 at 13:50
Using elementary linear algebra you can get a closed formula for the intersection coordinates. This should be somehow implemented in a command which calculates intersections of rays... –  student Oct 31 '12 at 15:00
add comment

## 2 Answers

You could cheat by intersecting the line p1 to p2 (called AB in the code sample below) with an "infinitely long" (e.g. one metre...) path that's not drawn. You have to reset the bounding box after defining the "ray", because otherwise your tikzpicture will too big.

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{intersections}
\usetikzlibrary{backgrounds} % Only used for showing the bounding box
\begin{document}

\begin{tikzpicture}[show background rectangle]
\coordinate (C) at (1,1);
\path [name path=Cray]
\foreach \n in {-45,-40,...,45}{ (C) -- +(\n:100cm) };
\pgfresetboundingbox

\draw [name path=AB] (3,-2) .. controls(10,0) and (8,5) .. (8,5);
\draw [red,name intersections={of=AB and Cray,sort by=AB,total=\t}]
\foreach \i in {1,...,\t} { (C) -- (intersection-\i) };
\end{tikzpicture}

\end{document}

-
add comment

A quick fix would be to create a point p4alt at some standard distance, say 1cm, from p3 and then use p3--p4alt in your intersection specification; no need to draw the point p4alt itself. If, say, e is at 115 degrees, you would use \draw (p3) ++(115:1cm) coordinate (p4alt) ; to set up the ray from p3.

-
add comment