I have some tikz code that draws a triangle with labelled verticies.
I would like to draw a line that starts at the origin, intersecting the point labelled P, and has a length equal to the edge labelled A.
I figure that the calc library is what I want for this, but I'm having trouble working out how to feed it the length of A...
Here is my code so far, with my best guess at what I think the edge I want to draw command will look like:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections, calc, through, backgrounds}
\begin{document}
\begin{tikzpicture}[scale=3]
% layout some coordinates for a triangle
\coordinate (P) at ($(0,0) + (rand,rand)$);
\coordinate (Q) at ($(2,-2) + .5(rand, rand)$);
\coordinate (R) at ($(-2, -2) + .5(rand, rand)$);
%convienience for finding the centre
\coordinate (PQR) at ($(P)+(Q)+(R)$);
\coordinate (O) at ($1/3*(PQR)$);
%draw triangle
\draw[name path=A] (P) -- (Q);
\draw[name path=B] (Q) -- (R);
\draw[name path=C] (R) -- (P);
%labels
\node at (O) {$O$};
\node at (P) [above=2pt]{$P$};
\node at (Q) [right=2pt]{$Q$};
\node at (R) [left=2pt]{$R$};
\node at ($(P)!.5!(Q)$) [above right=1em]{$\mathbf{A}$};
%draw a path of length (A) from (O), passing through (P)
%\draw[name path=U] (O) -- ($(O)! !(B)$)
\end{tikzpicture}
\end{document}




tkz-euclide, you can get the length of a segment with\tkzCalcLengthmacro. And not related, but finding the centroid is shorter with\coordinate (O) at (barycentric cs:P=1,Q=1,R=1) ;. – SebGlav Feb 12 '21 at 16:47