TransWikia.com

Middle of two coordinates

TeX - LaTeX Asked on February 19, 2021

In TikZ, I have defined two coordinates by

coordinate (A) (1, 2);
coordinate (B) (5, 3);

Is there a simple way to define the middle of A and B? I’m looking for a command such as

coordinate (M) (A)!0.5!(B);

Thanks

One Answer

As pointed out in the comments, this answer is mostly a reminder of Claudio Fiandrino's or Jake's answers.

To compute coordinates based on two other coordinates, TikZ proposes the calc library depicted in details in section §13.5 of the pgfmanual (accessible on CTAN or with texdoc pgfmanual.pdf if installed).

More specifically, the syntax required by the calc library to compute coordinates from others takes the form ($<coordinate 1>!<factor / dimension / coordinate>!<angle>:<coordinate 2>$) and fall under the scope of so-called Partway / Distance / Projection Modifiers.

Note the ($...$) enclosing which is required !

In your case, you are interested in the partway modification, because you try to compute the coordinates midway (hence at a 0.5-0.5 normalized distance) between two other ones.

In the end the syntax should therefore be coordinate (M) at ($(A)!0.5!(B)$); where

  • <coordinate1> = (A)
  • <factor> = 0.5 for the midway point
  • <angle> = {} so assumed null
  • <coordinate2> = (B)

Correct answer by BambOo on February 19, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP