4

I have a node (using TikZ and the shapes library)

\node (c0) [circle, draw] at (0,0) {foo};

and a coordinate

\coordinate (c1) at (4,2);

How can I draw a line from c1 to c0.north west such that the line first proceeds horizontally along the y coordinate of c1 (here 2), and then turn towards c0 at the appropriate point, so that it is normal to the circle when it hits c0.north west? Both segments are straight lines, with the bend being either sharp/rounded corners (it doesn't matter). Here's a simple sketch of the above:

enter image description here

1

1 Answer 1

3

You can choose an angle on the border of the node (no need for coordinates since their center is also the border coordinate) and use that to perform a simple calculation. Let's say we take 30 (north west is 135, second picture below and then 10) then we have

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\node (c0) [circle, draw] at (0,0) {foo};
\coordinate (c1) at (4,2);

\draw let \p1=($(c1)-(c0.30)$),\n1={\y1/sin(30)} in (c0.30)--++(30:\n1) -- (c1);

\end{tikzpicture}
\end{document}

enter image description here

enter image description here

enter image description here

You can further furnish this simple idea with a style, make angle a variable etc. Obviously you we want our angle to be in [0+ε,π-ε] for some small ε tolerance otherwise see you at infinity (which for me is the textwidth).

4
  • \p1 and \y1 intermixed?
    – Toscho
    Apr 21, 2013 at 10:33
  • @Toscho By intermixed you mean they need to be swapped? \p1 is the coordinate, \y1 is the vertical component of \p1
    – percusse
    Apr 21, 2013 at 10:36
  • Please ignore my previous, unqualified comment. I learned something new about tikz.
    – Toscho
    Apr 21, 2013 at 10:43
  • @Toscho Haha no problem at all.
    – percusse
    Apr 21, 2013 at 10:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .