# How do I place a coordinate midway between two other coordinates using tikz

I'm struggling to draw a diagram in tikz. I'm trying to do a simple illustration of a parallelogram inside an arbitrary quadrilateral.

I have the following code to place S halfway between O, and P.

Is there a way to do this? Ideally I would get a named coordinate that I can use for further drawing in the end

\documentclass{report}

\usepackage{tikz}
\usetikzlibrary{intersections, calc,through,backgrounds}

\begin{document}

\begin{tikzpicture}
%declare points OPQR at random locations
\coordinate[label=right:\textcolor{blue}{$O$}] (O) at ($(0,0) + 3*(rand, rand)$);
\coordinate[label=left:\textcolor{blue}{$P$}] (P) at ($(0,0) + -2*(rand, rand)$);

% I thought something like this would work, but it doesnt
%\coordinate[label=left:\textcolor{orange}{$S$}] (S) at ($0.5* ((O) - (P))$);

\draw[->, name path=A]  (O) -- (P);

\end{tikzpicture}

\end{document}


I also tried:

(O) -- coordinate[midway](S) (P);


but when I tried to draw a line from S to another point I got an error that pgf didn't know any shapes by the name S.

• With calc: ($(P)! 0.5!(Q)$) is midway between P and Q. Feb 7, 2021 at 9:48
• Have you put a \path in front of your last line of code? (btw: this is why we discourage using snippets of code, always use complete, compilable pieces of code.) Feb 7, 2021 at 9:53
• Finally: the midpoint between P and Q is 0.5*(P+Q), not 0.5*(P-Q)... ;-) Feb 7, 2021 at 9:57
• thanks, I have no idea what I'm doing with tikz, i thought it wouldn't be so hard to whip up a simple illustration, oh how wrong I was :P Feb 7, 2021 at 10:16
• I did strip out most of the fat, but there are no \path's left out (although i am intending to draw a line from each midpoint to each other midpoint now I have those worked out :P Feb 7, 2021 at 10:21

\coordinate (S) at ($(O)!0.5!(P)$); should solve your problem.

• indeed it does, thanks! Feb 7, 2021 at 10:15

It is not clear, what is the problem. With knowing of the coordinate S you draw a rectangle. It can be simply defined as follows:

\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{backgrounds,
calc,
intersections,
through}

\begin{document}
\begin{tikzpicture}
% declare points OPQR at random locations
\coordinate[label=right:\textcolor{blue}{$O$}] (O) at ($(0,0) + 3*(rand, rand)$);
\coordinate[label=left: \textcolor{blue}{$P$}] (P) at ($(0,0) + -2*(rand, rand)$);

\draw[->, name path=A]  (O) -- coordinate[label=left:\textcolor{orange}{$S$}] (S) (P);

\end{tikzpicture}
\end{document} 