Edit (The almost ultimate solution)
After sorting everything out and having some nice code - thanks to cjorssen :) - I cam up with a general solution with which you are able to use the connector with two arbitrary nodes: (The previous code needed the circled node to be at the origin (0,0).
%usage: \arcconnector[color]{Satellite Node}{Circled Node}{rim radius}
\newcommand\arcconnector[4][black]%
{%
\path [name path=S--C] (#2) -- (#3);
\path [name path=Rim] (#3.center) circle(#4);
\path [name intersections={of=S--C and Rim}];
\pgfmathanglebetweenpoints{%
\pgfpointanchor{#3}{center}}{%
\pgfpointanchor{intersection-1}{center}}
\let\myendresult\pgfmathresult
\path [draw,color=#1] (intersection-1) arc[start angle=\myendresult,delta angle=-40,x radius=#4,y radius=#4];
\path [draw,color=#1] (intersection-1) arc[start angle=\myendresult,delta angle=40,x radius=#4,y radius=#4];
\path [draw,#1] (#2) -- (intersection-1);
}
So for the example depicted below we can do this:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\node [shape=circle,draw,minimum size=1cm,red] (C) {};
\node at (0.8,1.5) [shape=rectangle,draw,blue] (P) {P};
\arcconnector{P}{C}{0.6cm}
\end{tikzpicture}
\end{document}
Another useful parameter that you may want to adjust is the length of the arc wings (here const 40°).
Edit (after first answer and comments)
I want to draw an arc at an intersection in that way, that the intersection is the middle of the arc. But I don't know how to define \myendresult
to be the angle between (Origin intersection-1) and the x-axis.
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\coordinate (Origin) at (0,0);
\coordinate (Xaxis) at (1,0);
% Note: the minimum size is the diameter, so radius = .5cm
\node [shape=circle,draw,minimum size=1cm,red] (C) {};
\node at (0.8,1.5) [shape=rectangle,draw,blue] (P) {P};
\path [name path=P--C] (P) -- (C);
\path [name path=Rim] (0,0) circle(0.6cm);
\path [name intersections={of=P--C and Rim}];
% How to define \myendresult?
%\path [draw] (intersection-1) arc[start angle=\myendresult,delta
% angle=-40,radius=0.6cm];
%\path [draw] (intersection-1) arc[start angle=\myendresult,delta
% angle=40,radius=0.6cm];
\path [draw] (P) -- (intersection-1);
\end{tikzpicture}
\end{document}
This should look like the following:
The base problem is to find the correct start angle for arc. Maybe this is also possible by using some tangent calculations?
Original question
The base problem is, that I'd like to compute the angle between two lines given by two coordinates in tikz
. That seems to be difficult and because one of the lines is the x-axis (1,0), we can reduce that to:
Calculate the asin from the y-value of the second coordinate (here intersection-1
).
But this seems to be a problem. I tried to use \pgfextracty
with \pgfmathasin
:
\newdimen\myyvalue
\pgfextracty{\myyvalue}{intersection-1}
\node at (1,1) {\myyvalue};
\pgfmathsetmacro{\myendresult}{asin(\myyvalue)}
\path [draw,blue] (intersection-1) arc[start angle=\myendresult,delta angle=30,x radius=0.6cm,y radius=0.6cm];
At line 3 I get "missing number treated as zero".
So I tried using the let
command:
\path [name intersections={of=A and B},draw,blue] let \p1=(intersection-1) in (intersection-1) arc[start angle=\pgfmathasin{\y1},delta angle=30,x radius=0.6cm,y radius=0.6cm] (intersection-1);
But now I get the error:
! Incomplete \iffalse; all text was ignored after line 821.
<inserted text>
\fi
I don't get the errors and am I little bit helpless. It seems no one else ever tried to compute the angle between to vectors/coordinates/points in tikz
(at least Google doesn't find anything).
!
in front of it to turn it into a link. A moderator or another user with edit privileges can then reinsert the!
to turn it into an image again.