EDIT: An inline calculation is seen in the bottom.
In principle it is. I haven't really optimized the below, it could be reduced somewhat.
You can utilize the let
operator (which also comes from the calc
library).
What you want to do is obtain the maximum y coordinate and then select the half x coordinate. So you need the x and y coordinates of each point.
Furthermore you should never specify a coordinate using a node
! This can give very unforseen problems. Remember that nodes retain a size, whereas coordinates does not.
I would do your system something like this:
\begin{tikzpicture}
\coordinate (A) at (0,0);
\node[above right] at (A) {A};
\coordinate (B) at (10,10);
\node[below left] at (B) {B};
\draw [draw=black] (A) rectangle (B);
\draw let \p1 = (A),
\p2 = (B),
\n{x} = {(\x1+\x2)/2},
\n{y} = {max(\y1,\y2)} in
(\n{x},\n{y}) node[above] {Top of Rect [incorrect]};
\coordinate (ABMid) at ($(A)!0.5!(B)$);
\node at (ABMid) {Midpoint AB};
\end{tikzpicture}
Of course, if you don't need the coordinate ABMid
then just do \node at ($(A)!.5!(B)$) {...};
What the above does is calculating on the path the x and y coordinate of your top point. \p<int> = (<coordinate>)
will save x and y in \x<int>,\y<int>
for further computation within the let
line. The \n{x}
line calculates the x-coordinate of your top point, and the \n{y}
line calculates the maximum y-coordinate.
The above will yield:

I realized that you really wanted something inline (which is doable but ugly).
So what you can do is project B
onto the vertical line starting in A
, then calculate the middle point between this and B
, that will give you the half way on the line you need.
So this can be done via this obscure construct:
\coordinate (ABMidTop) at ($(A)!(B)!($(A)+(0,1)$)!.5!(B)$);
\node[above] at (ABMidTop) {Top of Rect [incorrect]};
It should be read like this:
draw the line A
to A+(0,1)
, then project B
onto this line. Then take the halfway point between the previous calculated point and B
.