1

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.

6
  • 3
    With calc: ($(P)! 0.5!(Q)$) is midway between P and Q.
    – Rmano
    Feb 7, 2021 at 9:48
  • 1
    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.)
    – Rmano
    Feb 7, 2021 at 9:53
  • Finally: the midpoint between P and Q is 0.5*(P+Q), not 0.5*(P-Q)... ;-)
    – Rmano
    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

2 Answers 2

1

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

1
0

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}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.