# TikZ: can a new coordinate be placed along a line by using shorten?

I have line from the origin to (2,2) in this example where I placed the coordinate (A) at the (2,2). What I want to do is place a new coordinate 1cm below (A) on the same line and then draw a perpendicular line at the new location. Here is the code I have tried but it doesn't work properly.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\draw (0, 0) -- (2, 2) coordinate (A);
\coordinate[style = {shorten >= -1cm}] (P) at (A);
\draw (P) -- ($(P)!2cm!-90:(A)$);
\end{tikzpicture}
\end{document}


As you can see, I tried shortening the coordinate, but when I drew a line at the new location (P) it drew a line directly up from (A).

For the sake of this question, don't assume the line angle is unknown since here it is a nice 45 degrees. If that was the case, we could probably do something like (A) ++(225:1cm) coordinate (P), but in my real problem, we don't have the luxury of something so clean to work with.

Desired result:

Edit 2:

So this code comes close by stopping the line 1 cm short but the (P) coordinate is still being placed where (A) is when I need (P) to be placed at the end of the red line.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\draw (0, 0) -- (2, 2) coordinate (A);
\draw[shorten >= 1cm, red] (0, 0) -- (2, 2) coordinate (P);
\draw[blue] (P) -- +(1, 0);
\end{tikzpicture}
\end{document}


• To answer the question in the title: "No". – Andrew Stacey Jul 10 '13 at 18:48

You can use the calc library functions for interpolate between two points and then use the rotation for going orthogonally to the path

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\draw (0,0) coordinate (O) -- (3.72,2.46) coordinate(A);
\draw ($(O)!0.699!(A)$)coordinate (P) -- ($(P)!1cm!-90:(A)$);
\end{tikzpicture}
\end{document}


With absolute distances:

\documentclass{article}
%\url{http://tex.stackexchange.com/q/123469/86}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\draw (0, 0) coordinate (O) -- (2, 2) coordinate (A);
\coordinate (P) at ($(A)!1cm!(O)$);
\draw (P) -- ($(P)!2cm!-90:(A)$);
\end{tikzpicture}
\end{document}

• @dustin You said the angle is not trivial and 47 seemed nontrivial for me. – percusse Jul 10 '13 at 18:29
• @dustin The angle doesn't matter remove the angle part and define (A) whereever it might be. I've changed the point (A) to be arbitrary. – percusse Jul 10 '13 at 18:32
• @dustin Change the 0.699 with the distance you want then it will obey the distance instead of the path fraction. If you want to measure it from (A) then swap the order of (O) and (A). – percusse Jul 10 '13 at 18:44
• I've added the absolute distance version (seemed overkill for a separate answer). – Andrew Stacey Jul 10 '13 at 18:47

With PSTricks. Just for fun!

## Case 1:

To define P which is radially 1 unit below A, use ([nodesep=1]{O}A). To define a point through which a line passes and the line is perpendicular to OA, use ([nodesep=1,offset=2]{O}A).

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-eucl}
\begin{document}
\begin{pspicture}[showgrid](-1,-1)(3,3)
\pstGeonode
(0,0){O}
(2,2){A}
([nodesep=1]{O}A){P}
\psline[linecolor=red](O)(A)
\psline[linecolor=blue](P)([nodesep=1,offset=2]{O}A)
\end{pspicture}
\end{document}


## Case 2:

To define P which is vertically 1 unit below A, use ([Ynodesep=1]{O}A). To define a point through which a line passes and the line is perpendicular to OA, use ([Ynodesep=1,offset=2]{O}A).

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-eucl}
\begin{document}
\begin{pspicture}[showgrid](-1,-1)(3,3)
\pstGeonode
(0,0){O}
(2,2){A}
([Ynodesep=1]{O}A){P}
\psline[linecolor=red](O)(A)
\psline[linecolor=blue](P)([Ynodesep=1,offset=2]{O}A)
\end{pspicture}
\end{document}
`

• How about TikZ? – dustin Jul 10 '13 at 18:25