I am trying to draw three congruent, equilateral triangles unicursally in TikZ (see figure below). Per se, this is rather simple, but I want to write the TikZ code so that I can easily change the shape of the figure by adjusting a few geometrical parameters. More specifically, I want the coordinates in the TikZ figure to vary, depending on the value of the parameters.
The two parameters I want to change are the distances from a to q (later referred to as L) and from q to b (later referred to as Δ) in the figure above. By choosing a to be the origin, the expressions for the coordinates will be as follows
a: ( 0 , 0 )
b: ( cos(60°)*(L + Δ) , sin(60°)*(L + Δ) )
c: ( bx + cos(60°)*L , by - sin(60°)*L )
d: ( L - cx , cy )
e: ( L - bx, by )
f: ( L , 0 )
where bx, by, cx and cy denote the x and y coordinates of points b and c respectively. (The coordinates of q are not necessary in order to draw the figure.)
I tried the following approach, but this gives the output shown below, where only the coordinates of a and f are correct. If this had worked, I would be able to simply change the definitions of \l
and \delta
and recompile to see how the geometry changes with L and Δ.
\begin{tikzpicture}
\def\cossixty{0.5}
\def\sinsixty{0.866025}
\def\l{6}
\def\delta{2}
\def\ldelta{\l+\delta}
\def\bx{\cossixty*\ldelta}
\def\by{\sinsixty*\ldelta}
\def\cx{\bx+\cossixty*\l}
\def\cy{\by-\sinsixty*\l}
\def\dx{\l-\cx}
\def\ex{\l-\bx}
\coordinate (a) at (0,0);
\coordinate (b) at (\bx,\by);
\coordinate (c) at (\cx,\cy);
\coordinate (d) at (\dx,\cy);
\coordinate (e) at (\ex,\by);
\coordinate (f) at (\l,0);
\begin{scope}[thick]
\draw (a) -- (b) -- (c) -- (d) -- (e) -- (f) -- (a);
\end{scope}
\end{tikzpicture}
So my question is this: how can I make TikZ compute the coordinate expressions listed above into floating point numbers and get the correct output?
(This is only a small part of a larger image which I am to make in TikZ, so there is, of course, a good reason why I choose to draw the figure unicursally, and with adjustable parameters.)
Best Answer
You code works just fine once you let
pgf
do the math for you:Notes:
\delta
is a greek letter so better to use a different name.node
to label the two parameters.Code: