2

I'd like to draw a line, with the same angle (to calculate) of a given one. Here's what I tried to do

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{decorations.markings,calc,angles,quotes}
\begin{document}
\begin{tikzpicture}
\coordinate (O) at (-1,0);
\coordinate (P) at ($ (O) + (0,1) $);
\coordinate (A) at (-4,0);

\draw ($ (A) + (-0.5,0) $) -- ($ (O) + (0.5,0) $);
\draw [->, ultra thick] (O) -- (P);         
\draw [thick, dashed] (A) -- (P);

\begin{scope}[shift=(A)]
    \draw [thick] let \p=(P), \n={atan2(\y,\x)} in (P) -- (\n:3);           
\end{scope}
\end{tikzpicture}
\end{document}

but it gives me back this message: "Cannot parse this coordinate" (the problem is at "\draw ... let ... in ..." line. What am I doing wrong? What i want to do it's something like this:

enter image description here

I can't use "shorten" as an option of \draw command cause the lines have 2 different styles (for example one is dashed, the other is thick).

2 Answers 2

2

Welcome! Like this?

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate (O) at (-1,0);
\coordinate (P) at ($ (O) + (0,1) $);
\coordinate (A) at (-4,0);

\draw ($ (A) + (-0.5,0) $) -- ($ (O) + (0.5,0) $);
\draw [->, ultra thick] (O) -- (P);         
\draw [thick, dashed] (A) -- (P);

\begin{scope}[shift={(A)}]
    \draw [thick] let \p1=(P), \n1={atan2(\y1,\x1)} in (P) -- ++(\n1:3);           
\end{scope}
\end{tikzpicture}
\end{document}

enter image description here

2
  • oh wow, i swear i wrote "hi everyone"... excuse me for that irruption. Yes that's it! I can't believe i missed that "1"... thank you!
    – frad
    Dec 22, 2019 at 21:05
  • @user203430 You're welcome! There were two more things: (A) needs to be in braces in \begin{scope}[shift={(A)}], and there need to be ++ before (\n1:3) if you wish to extend the line.
    – user194703
    Dec 22, 2019 at 22:05
1

For old users, before the birth of let \n \p etc... we used some tricks like this

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{decorations.markings,calc,angles,quotes}
\begin{document}
\begin{tikzpicture}
\coordinate (O) at (-1,0);
\coordinate (P) at ($ (O) + (0,1) $);
\coordinate (A) at (-4,0);

\draw ($ (A) + (-0.5,0) $) -- ($ (O) + (0.5,0) $);
\draw [->, ultra thick] (O) -- (P);         
\draw[thick, dashed] (A) -- (P) \pgfextra{\pgfinterruptpath\draw [red](P) -- ($(A)!1.5!(P)$);\endpgfinterruptpath} ; 

\end{tikzpicture}
\end{document}

enter image description here

You must log in to answer this question.

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