TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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

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.

\usetikzlibrary{backgrounds} % Only used for showing the bounding box

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

\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) };


rays intersecting a line in tikz

share|improve this answer

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.