This question has two parts:
why is the angle computed always 0 (should be 45)
what is a straightforward way to compute distance between coordinates (there is How can I compute the distance between two points in TikZ, though I was hoping for something easier, posibly via defining
\coordinate
for both points and getting their distance.
The application I have in mind is to define a scope
with local coordinate system with origin in A
and local +x axis having the direction B-A
. If there is an easier way for that, I will be happy to discover it.
\documentclass{minimal}
\usepackage{tikz}
\begin{document}
\tikz{
\def\A{(1,1)}
\def\B{(2,2)}
%% {1} this returns 0.0 although it should be 1.414213...
\pgfmathanglebetweenpoints{(1,0)}{\B-\A}
\let\abAngle\pgfmathresult
%% {2} how to compute eyclidean distance of coordinates?
%% we would have to extract x and y components of B-A to be able to use \pgfveclen{}{}
%\pgfveclen{??}{??}
\let\abLength\pgfmathresult
\message{|\B-\A| = \abLength, angle between +x and (\B-\A) = \abAngle}
}
\end{document}
with the result:
|(2,2)-(1,1)| = 0.0, angle between +x and ((2,2)-(1,1)) = 0.0
\pgfmathanglebetweenpoints
. This macro gives the angle formed by a line AB with the axe x'x or (1,0) if you prefer. You need only to give two points with coordinates (\pgfpoint
is possible butpgfpointanchor
is very useful.