# intersection coordinate systems

I'm trying to write a \newcommand to draw a little stick-man in PGF. It isn't finished yet, but right now, it looks like this:

\newcommand{\man} {
% #1 : The position of the head of the stick man
\coordinate (X) at (#1);
\coordinate (Y) at ($(#1)+(0,1mm)$);
\draw [black,fill=green,thin] ($(#1)+(290:2mm)$) arc (-70:240:2mm)--++(-3mm,0)--++(0,-1mm)
--++(3mm,0)--++(0,-3mm)--++(225:3mm)--++(315:1mm)coordinate(A)--++(45:1mm)coordinate(B)--
(intersection of A--B and X--Y)--
(#1)--cycle;
}


The function input #1 is the center of his head. The path starts off on the right side of his head, draws an arc (his head) to the left side, then traces his left arm, and the left side of his body. When it comes to his leg, I switch to using polar coordinates, because I want his leg to extend out at 45 degrees. The question arises on the way back from drawing his left leg. I want his crotch (for lack of a better word) to be directly below the center of his head. So I'm trying to find a way to define the point that lies on the intersection of the vertical line through (#1) and the line at 45 degrees through (A).

Right now I have to define coordinates (X) and (Y) ahead of time, which define the vertical line through the center of his head. and I have to define (A) and (B) on the path to define the line at 45 degrees along his leg. I can then use (intersection of A--B and X--Y). My question is, can I do this more elegantly without needing to define these extraneous coordinates (X), (Y) and (B)?

I tried things like

(intersection of A--$A+(45:1mm)$ and X--$X+(0,1mm)$)


but that didn't work.

As per Peter's comment, here is a minimum working example:

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand{\man} {
% #1 : The position of the head of the stick man
\coordinate (X) at (#1);
\coordinate (Y) at ($(#1)+(0,1mm)$);
\draw [black,fill=green,thin] ($(#1)+(290:2mm)$) arc (-70:240:2mm)--++(-3mm,0)--++(0,-1mm)
--++(3mm,0)--++(0,-3mm)--++(225:3mm)--++(315:1mm)coordinate(A)--++(45:1mm)coordinate(B)--
(intersection of A--B and X--Y)--
(#1)--cycle;
}

\begin{document}
\tikz{\man{3,3}}
\end{document}

• Intersections requires path names, not lines. A basic example is at TikZ: Intersection of two lines. Also, while code snippets are useful in explanations, it is always best to compose a fully compilable MWE that set up the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. – Peter Grill Jun 28 '13 at 6:51
• @PeterGrill Not true, see TikZ intersection command not returning desired result (also related to OP’s question) and my comment to question linked by you. @OP: You can: (intersection of A--[shift={(45:1mm)}]A and X--[shift={(0,1mm)}]X). Your original calc supported way, works too, if you a) enclose A and X in parentheses and the whole in braces: (intersection of A--{$(A)+(45:1mm)$} and X--{$(X)+(0,1mm)$}) – Qrrbrbirlbel Jun 28 '13 at 7:23
• On the other hand: What is wrong with defining coordinates “ahead of time”? Could you add an image of what the output should look like? – Qrrbrbirlbel Jun 28 '13 at 7:29
• @Qrrbrbirlbel: Thanks for your help on the shift, it works. Regarding defining coordinates ahead of time, I guess it's a matter of personal preference, but I prefer to have the path to be self-contained rather than depend on outside help. I've completed the stick man, it looks ok, but I'm not sure how to post it in this forum – Chah Jun 28 '13 at 7:42
• @Chah If you find an answer yourself, post it below. Regarding the elegance, you can do that all in one path. Still, the auxiliary coordinates are needed but if you use very obscure names for them, you won’t have any troubles. – Qrrbrbirlbel Jun 28 '13 at 7:57

This is as elegant as I get (without pre-calculating anything).

First: no calc library. The ($(#1)+(#2)$) syntax translates to ([shift={(#1)}] #2) = ([shift={(#2)}] #1).

The pelvis area has been created with two auxiliary coordinates and the intersection of syntax.

Also, I find it more elegantly to use TikZ possibilited and created an insert path style. (You can of course simply translate it back to an own command.

## Code

\documentclass[tikz,convert=false]{standalone}
\tikzset{
man/.style={
insert path={
([shift={(+-60:+2mm)}]#1) arc[radius=+2mm, start angle=+-60, end angle=+240] --
++(left: +3mm) --
++(down: +1mm) --
++(right:+3mm) --
++(down: +3mm) --
++(225:  +3mm) --
++(315:  +1mm) coordinate (@aux1) --
++(45:   +1mm)  --
(intersection of #1--[shift={(down:+1cm)}] #1 and @aux1--[shift={(+45:+1cm)}]@aux1)
coordinate (@aux2) --
(intersection of @aux1--[shift={(right:+1cm)}]@aux1 and @aux2--[shift={(+-45:+1cm)}]@aux2) --
++(45:   +1mm) --
++(135:  +3mm) --
++(up:   +3mm) --
++(right:+3mm) --
++(up:   +1mm) -- cycle
}
}
}
\begin{document}
\tikz \path[draw=black,fill=green,thin,line join=round] [man={3,3}];
\end{document} 