# Could I name a number in tikz?

I have been drawing some pictures using tikz, and am wondering if I can name a number.

For example, I pick a point $A$ with position angle $\alpha=45\degree$ on a circle, and a line going through that point with direction angle $\beta=\alpha+90\degree=135\degree$ (wich is perpendicular to the position vector).

Later I change the point $A$ to be $\alpha=60\degree$, and then $\beta=150 \degree$.

Now I change both angles manually. If I can name the first angle $\alpha$ and the second angle $\beta$, then I only need to change $\alpha$: $\beta$ will vary accordingly.

Is there a way to do this, naming a number? Thanks!

• I didn't understand correctly. Can you add an example of what you want to achieve in the end but can't? – AndréC Dec 25 '18 at 17:15
• Named numbers are called variables or constants. But named points may be named as nodes. – Artificial Stupidity Dec 25 '18 at 18:01

## 4 Answers

You can also use tikzmath from math tikzlibrary

    \documentclass[border=1cm,multi]{standalone}
\usepackage{tikz}
\usetikzlibrary{math,angles,quotes}

\begin{document}
\tikzmath{
\R=2; % circle radius
\d=3; % distance between A and B
\a1=30; % angle alpha
\a2=\a1 + 90; % angle beta
}
\begin{tikzpicture}
\draw (0,0)circle[radius=\R cm];
\path (\a1:\R) coordinate[label=$$A$$] (A) +(\a2:\d)coordinate[label=$$B$$](B);
\draw (A)--(B);

\coordinate(O) at(0,0);
\coordinate(x) at(1,0);
\draw(x)--(O)--(A);
\pic[draw,"$$\alpha=\a1$$",angle eccentricity=2.25]{angle=x--O--A};

\end{tikzpicture}
\tikzmath{
\R=2; % circle radius
\d=3; % distance between A and B
\a1=60; % angle alpha
\a2=\a1 + 90; % angle beta
}
\begin{tikzpicture}
\draw (0,0)circle[radius=\R cm];
\path (\a1:\R) coordinate[label=$$A$$] (A) +(\a2:\d)coordinate[label=$$B$$](B);
\draw (A)--(B);

\coordinate(O) at(0,0);
\coordinate(x) at(1,0);
\draw(x)--(O)--(A);
\pic[draw,"$$\alpha=\a1$$",angle eccentricity=2.25]{angle=x--O--A};

\end{tikzpicture}
\end{document}


If I understood correctly, you want to place a point A on a circle at a certain angle and then a point placed on the perpendicular to this 90 degree radius.

Then you want these two angles to be relative. It is possible to define a constant with the LaTeX macro \def and to define the other one with the calc library which allows to place a point with respect to two others with a given angle (see pages 143 and 144 of the manual 3.0.1a).

Here is an example:

\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{calc}
\begin{document}
\def\alpha{45}

\begin{tikzpicture}[]
\draw (0,0)circle (2cm)circle(1pt);
\draw  (\alpha:2) coordinate(A)circle(1pt);
\draw ($(A)!1!-90:(0,0)$)--($(A)!1!90:(0,0)$);
\end{tikzpicture}

\end{document}


And as a Christmas gift, a little animation:

\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{calc}
\begin{document}
\def\alpha{40}
\foreach \alpha in {0,5,...,180}{
\begin{tikzpicture}[]
\useasboundingbox (-3,-3) rectangle (3,3);
\draw (0,0)circle (2cm)circle(1pt);
\draw  (\alpha:2) coordinate(A)circle(1pt);
\draw ($(A)!1!-90:(0,0)$)--($(A)!1!90:(0,0)$);
\end{tikzpicture}
}
\end{document}

• Thanks a lot. Now I know how to create a gif! – Pengfei Dec 25 '18 at 19:32

You can use insert path in order to insert paths that are largely the same. This is illustrated in the MWE most of which is illustration.

\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}[insert points/.style={insert path={%
(#1:1) coordinate(A) (#1+90:1) coordinate(B)}}]
% with 45 degrees
\path[insert points=45];
% only illustration
\draw circle (1);
\foreach \X in {A,B}
{\node[fill,inner sep=1pt,label=right:\X] at (\X){};}
% second example (shifted to avoid interference)
\begin{scope}[xshift=4cm]
% with 60 degrees
\path[insert points=60];
% only illustration
\draw circle (1);
\foreach \X in {A,B}
{\node[fill,inner sep=1pt,label=right:\X] at (\X){};}
\end{scope}
\end{tikzpicture}
\end{document}


A PSTricks solution only for fun purposes.

# Still image

\documentclass[pstricks,12pt]{standalone}
\usepackage{pst-eucl}
\begin{document}
\pspicture(8,8)
\pstGeonode(4,4){O}([nodesep=2,angle=60]O){A}([offset=-2]{O}A){X}([offset=2]{O}A){Y}
\pstCircleOA{O}{A}
\psline(X)(Y)
\endpspicture
\end{document}


# Animated

\documentclass[pstricks,12pt]{standalone}
\usepackage{pst-eucl}
\begin{document}
\foreach \i in {0,30,...,330}{%
\pspicture(8,8)
\pstGeonode(4,4){O}([nodesep=2,angle=\i]O){A}([offset=-2]{O}A){X}([offset=2]{O}A){Y}
\pstCircleOA{O}{A}
\psline(X)(Y)
\endpspicture}
\end{document}