# Computation logic of Partway in TikZ

PGF Manual pg. 66 describes about Partway Calculations. In this example, ($(A)!.5!(B)$), .5 refers to 50% right? A point that is 50% away from point A. In that case, why do we require point B in the calculation. We can always use the first point for relative positioning. The comparison is made to xcolor package, which is not right (e.g orange!50!black. Here, the color would be 50% of orange and 50% of black. The second color is mandatory.) This comparison is not right and I would like to understand the purpose of providing the second point in the calculation.

Secondly, the computation of D is also not convincing:

After computing X, we can simply say, place point D above X at a distance of 6pts. It should also be equivalent to:

($(X) ! {sin(60)*2} ! 90:(B)$) right?

Please clarify and help me understand this tricky concept.

Why do we need (B) at the (X) calculation?

Look at this code

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate [label=left:$A$]  (A) at (0,0);
\coordinate [label=right:$B$] (B) at (1.25,0.25);
\draw (A) -- (B);
\node [fill=red,inner sep=1pt,label=below:$X$] (X) at ($(A)!.5!(B)$) {}; % (1)
\coordinate[label=above:$C$] (C) at (1,2);
\draw (A) -- (C);
\node [fill=red,inner sep=1pt,label=left:$Y$] (Y) at ($(A)!.5!(C)$) {}; % (2)
\end{tikzpicture}
\end{document} If (B) were unnecessary, (1) and (2) must have the same effect, i.e. (X) and (Y) must be the same. In fact, they aren't. Therefore (B) is necessary.

For more information, (B) stands for the ending point of the segment on which (X) is marked.

For the second code

Look at this

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate [label=left:$A$]  (A) at (0,0);
\coordinate [label=right:$B$] (B) at (1.25,0.25);
\draw (A) -- (B);
\node [fill=red,inner sep=1pt,label=below:$X$] (X) at ($(A)!.5!(B)$) {};
\node [fill=red,inner sep=1pt,label=above:$D$] (D) at ($(X)!{sin(60)*2}!90:(B)$) {};
\coordinate[label=right:$C$] (C) at (1,-2);
\draw (A) -- (C);
\node [fill=red,inner sep=1pt,label=left:$Y$] (Y) at ($(A)!.5!(C)$) {};
\node [fill=red,inner sep=1pt,label=below:$E$] (E) at ($(Y)!{sin(60)*2}!90:(C)$) {};
\end{tikzpicture}
\end{document} Again the same reason as above: (B) must be crucial otherwise (D) and (E) must be the same.

• Joulev we can use above and other anchors right Instead of the sin calculation. That would make it simpler. That is my actual query for the second question – subham soni Mar 9 at 14:00
• @subhamsoni Of course using sin is not the only way to draw that. As the section in the manual is about Partway Calculations, the author uses sin in the example. In my case I would not use sin. – user156344 Mar 9 at 14:02

The purpose of the TikZ manual tutorials is to introduce the most useful concepts and library to get started with TikZ. And not to give the best way to build the figures.

### First question: In that case, why do we require point B in the calculation?

Because in plane geometry, there is an infinity of points located at the same distance from a given point: these are the points of a circle.

By example, in the figure below, points M and N are located 2 cm from the centre of the circle. It is therefore necessary to indicate a second point B. ### Second question: Please clarify and help me understand this tricky concept

This passage illustrates the use of the calc library. For this example, he uses geometric relationships in the equilateral triangle to place point D.

Personally, I would have built this triangle using polar coordinates, then rotating. The aim here is not to make it as simple as possible, but to present TikZ's main concepts and libraries. \documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{calc}
\begin{document}

\begin{tikzpicture}
\draw[rotate=10] (0,0)coordinate(A)--(2,0)coordinate(B)--(60:2)coordinate(D)--cycle;
\node[left] at (A){A};
\node[right] at (B){B};
\node [above] at (D) {D};
\end{tikzpicture}
\end{document}


Translated with www.DeepL.com/Translator

In this example, ($(A)!.5!(B)$), .5 refers to 50% right?

Correct. It's simply another notation.

A point that is 50% away from point A. In that case, why do we require point B in the calculation.

Wrong. If you take the path from A to B, then the 50% denote that you move only 50% along that path (starting at point A) maintaining the direction. Or even easier: Take the vector (b-a), scale it with 0.5 and add it to a. Then you have your new coordinate.

Without the second part the direction would be unspecified. That is, you would not know whether you should move upwards or sidewards or downwards. In turn you could not uniquely identify the destination which would not be what you want when drawing a picture.

• thanks. Can you please clarify the second point. – subham soni Mar 9 at 13:27
• @subhamsoni Without knowing the direction a distance says nothing. Should (a)!.5 point upwards, sidewards, …? That wouldn't be clear. – TeXnician Mar 9 at 15:01