How do I combine the !.5! operator with the -| operator?
I want a node that has x-coordinate equal to the average of x coordinates of nodes A and B, and a y-coordinate equal to the average the y coordinates of nodes C and D.
|
How do I combine the I want a node that has x-coordinate equal to the average of x coordinates of nodes A and B, and a y-coordinate equal to the average the y coordinates of nodes C and D. |
||||
|
|
|
I don't think you can directly mix the
|
|||||
|
|
Looking at the code, Jake is right in spirit but not in fact. It is possible to mix calc stuff (ie To know how this works, we have to know a bit about how TikZ parses coordinates. There are so many ways of specifying a coordinate that TikZ has to know about! So it looks for clues. One of the first clues is as to whether the coordinate (after the opening parenthesis) has a dollar. If it does, it hands it off to the So, our task (should we choose to accept it) is to figure out a way to specify a coordinate of the form At the end of all that, a little experimenting shows that we need two groups for the first coordinate and just one for the second. Hence:
does what it says on the tin. The reason that I really do not recommend this is that if the implementation changes, the number of groupings might change; and it is even feasible that this would no longer work. For that reason, I also have a solution for you which uses pure
In short, we project the coordinate at Here's some sample code with both of the above. I've put one below and one above to show them separately. The rectangle is to show that these are at the right places.
Result:
(My filename for this hack is |
|||||
|
|
I did it in pieces:
|
|||||
|
|
I may be late to the party, but there are other possibilities to get to that special point. The first one uses the The other solution has defined The advantage of these solutions is that you can re-use the calculated values in the same path ( One could write additional styles/codes/macros that define extra macros instead of Code
Output
|
||||
|
|
|
I may be even later to the party :-), but there is still some option that has not been discussed yet: Using the
instead of
There is a generalized lesson behind this: Remember that TikZ has a common syntax for all coordinate systems. Coordinates are specified (see §13 of the PGF Manual) by:
For convenience, TiKZ specifies a lot of "magic" operators (such as In these cases it often helps to simplify the job of the parser by refactoring parts of the expression into the general coordinate syntax.
|
||||
|
|