tikz add tag
Anonymous 1123
I want to draw sphere with centre at O(0,0,0) and passing the point A(2,3,6). I tried

```
\documentclass[border=2mm,12pt,tikz]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{calc}
\begin{document}
    \tdplotsetmaincoords{60}{70}
    \begin{tikzpicture}[tdplot_main_coords]
    \path
    (0,0,0) coordinate (O)
     (2,3,6) coordinate (T);
    \draw[tdplot_screen_coords] (O) let   \p1 = ($ (T) - (O) $) in circle ({veclen(\x1,\y1,\z1)});
\end{tikzpicture}
   \end{document}
```
I can not get the result. Where is wrong in that code?

Top Answer
user 3.14159
The `veclen` function only takes two arguments. However, it is possible to define pgf functions that take arbitrarily many arguments. Existing examples include the `max` function, which in its original version also was restricted to two arguments. Using the the definition of `max` I define a function `Veclen` which takes arbitrarily many arguments.

```
\documentclass{article}
\usepackage{pgf}
\makeatletter
\pgfmathdeclarefunction{Veclen}{...}{%
    \begingroup%
		\edef\pgfutil@tempa{0}\relax%
        \pgfmathVeclen@@#1{}}

\def\pgfmathVeclen@@#1{%
    \def\pgfmath@temp{#1}%
    \ifx\pgfmath@temp\pgfmath@empty%
        \let\pgfmath@next=\pgfmathVeclen@@@%
    \else%
		\pgfmathsetmacro\pgfutil@tempa{\pgfutil@tempa+#1*#1}%
		\pgfmath@x=\pgfutil@tempa pt\relax%
        \let\pgfmath@next=\pgfmathVeclen@@%
    \fi%
    \pgfmath@next}
\def\pgfmathVeclen@@@{\pgfmathsetmacro\pgfutil@tempa{sqrt(\pgfutil@tempa)}%
\pgfmath@x=\pgfutil@tempa pt\relax%
\pgfmath@returnone\pgfmath@x\endgroup}%
\makeatother
\begin{document}
\noindent\pgfmathparse{veclen(1,2)}\pgfmathresult\par

\noindent\pgfmathparse{Veclen(1,2)}\pgfmathresult\par

\noindent\pgfmathparse{Veclen(1,2,3)}\pgfmathresult\par

\noindent\pgfmathparse{sqrt(14)}\pgfmathresult\par
\end{document}
```

![Screen Shot 2020-08-05 at 11.26.39 AM.png](/image?hash=2b653d12acdf4cceb27a2884dbec62724daddc1829201395f4dad34d3ea2b459)

Please note that the currently existing function `veclen` has other deficiencies. It cannot be switched to fpu mode. It may thus be worthwhile to place a feature request to change it to something along the lines outlined above.

Another feature request would be to record the screen depth of each coordinate.  Currently, `tikz` has access to the screen coordinates only. It is, in principle, possible to computed and record the screen depth. However, it is very unlikely that such a feature request will be successful.  

However, you could use the fact that functions declared with `declare function` can also be arrays. So you can access the components and use them for operations such as the computation of a distance.
```
\documentclass[border=2mm,12pt,tikz]{standalone}
\usepackage{tikz-3dplot}
\makeatletter
\pgfmathdeclarefunction{tddistance}{2}{%
\begingroup%
\pgfmathparse{%
sqrt(({#1}[0]-{#2}[0])*({#1}[0]-{#2}[0])+({#1}[1]-{#2}[1])*({#1}[1]-{#2}[1])+({#1}[2]-{#2}[2])*({#1}[2]-{#2}[2]))}%
\pgfmathsmuggle\pgfmathresult\endgroup%
}%
\makeatother
\tikzset{coorf/.style={insert path={({{#1}[0],{#1}[1],{#1}[2]})}}}
\begin{document}
\tdplotsetmaincoords{60}{70}
\begin{tikzpicture}[tdplot_main_coords,
	declare function={O={0,0,0};T={2,3,6};}]
    \path
     [coorf=O] coordinate (O)
     [coorf=T] coordinate (T);
	\draw (O) -- (T) node[midway,sloped] {%
	\pgfmathparse{tddistance("O","T")}%
	\pgfmathprintnumber\pgfmathresult}; 
\end{tikzpicture}
\end{document}
```

![Screen Shot 2020-08-05 at 8.52.04 PM.png](/image?hash=8d7d54c3938fd20fb4bd1c9a700f53ff3aad0983d36041b9b298213f4756c94e)
Answer #2
Anonymous 1123
I used `\usetikzlibrary{3dtools}` and tried
```
\documentclass[border=2mm,12pt,tikz]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{calc}
\usetikzlibrary{3dtools}
\begin{document}
    \tdplotsetmaincoords{60}{70}
    \begin{tikzpicture}[tdplot_main_coords]
    \path
    (0,0,0) coordinate (O)
     (2,3,6) coordinate (T);
    \pgfmathsetmacro{\R}{sqrt(TD("(T)-(O)o(T)-(O)")};
\begin{scope}[tdplot_screen_coords]
\draw[blue, thick] (O) circle[radius=\R];
\end{scope}
 \foreach \p in {O,T}
{\draw[fill=black] (\p) circle (1.5pt);}
\foreach \p/\g in {O/90,T/90}
{\path (\p)+(\g:3mm) node{$\p$}; }
\end{tikzpicture}
   \end{document}
```
![ScreenHunter 791.png](/image?hash=eb242d7b5b607ac7ff5685a2c87b0f472c38a5f9d62f6e780554e5b363338331)

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.