TikZ PGF – Automatic Calculation of TikZ Coordinates

coordinatestikz-pgf

Right now I have these defined:

\coordinate (Z1) at (0.9,0.5);
\coordinate (Z2) at (0.816,-0.112);
\coordinate (Z3) at (0.46848,-0.46336);

But I would really like to automate this to be:

enter image description here

so that I can just specify Z1 and then vary the α factor easily to get Z2 and Z3. (Right now α = 0.8)

What's the simplest way to do this? I know how to do some coordinate calculations but this is beyond my skillset right now.


edit: FWIW(For what it's worth) this can also be expressed as a coordinate transformation H = [1 alpha; -alpha 1]/(1+alpha^2) so maybe that's something worth using. I don't know how to force tikz to compute transformed coordinates.

Best Answer

You could do something like this:

\documentclass[border=3mm,tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\pgfmathsetmacro{\Xi}{0.9}
\pgfmathsetmacro{\Yi}{0.5}
\pgfmathsetmacro{\Coeff}{0.8}

\pgfmathsetmacro{\Xii}{(\Xi+\Coeff*\Yi)/(1+\Coeff^2)}
\pgfmathsetmacro{\Yii}{(\Yi-\Coeff*\Xi)/(1+\Coeff^2)}
\pgfmathsetmacro{\Xiii}{(\Xii+\Coeff*\Yii)/(1+\Coeff^2)}
\pgfmathsetmacro{\Yiii}{(\Yii-\Coeff*\Xii)/(1+\Coeff^2)}

\coordinate (Z1) at (\Xi,\Yi);
\coordinate (Z2) at (\Xii,\Yii);
\coordinate (Z3) at (\Xiii,\Yiii);

\draw (Z1) -- (Z2) -- (Z3);

\end{tikzpicture}
\end{document}

Version with 4-argument macro:

\documentclass[tikz,border=2mm]{standalone}
\newcommand{\defcoords}[4][Z]{%
\pgfmathsetmacro{\Xi}{#2}
\pgfmathsetmacro{\Yi}{#3}
\pgfmathsetmacro{\Coeff}{#4}

\pgfmathsetmacro{\Xii}{(\Xi+\Coeff*\Yi)/(1+\Coeff^2)}
\pgfmathsetmacro{\Yii}{(\Yi-\Coeff*\Xi)/(1+\Coeff^2)}
\pgfmathsetmacro{\Xiii}{(\Xii+\Coeff*\Yii)/(1+\Coeff^2)}
\pgfmathsetmacro{\Yiii}{(\Yii-\Coeff*\Xii)/(1+\Coeff^2)}

\coordinate (#11) at (\Xi,\Yi);
\coordinate (#12) at (\Xii,\Yii);
\coordinate (#13) at (\Xiii,\Yiii);
}

\begin{document}
\begin{tikzpicture}
\defcoords{0.9}{0.5}{0.8}
\draw (Z1) -- (Z2) -- (Z3);

\defcoords[C]{0.9}{0.5}{2}
\draw (C1) -- (C2) -- (C3);
\end{tikzpicture}
\end{document} 
Related Question