I am wanting to use the code provided by Tom Bombadil to 3D bodies in TikZ that creates nice looking spheres, namely (with a slight adaption for showing the radius):
\draw (-1,0) arc (180:360:1cm and 0.5cm);%
\draw[dashed] (-1,0) arc (180:0:1cm and 0.5cm);%
\draw (0,1) arc (90:270:0.5cm and 1cm);%
\draw[dashed] (0,1) arc (90:-90:0.5cm and 1cm);%
\draw (0,0) circle (1cm);%
\shade[ball color=blue!10!white,opacity=0.20] (0,0) circle (1cm);%
\fill[fill=black] (0,0) circle (1pt);%
\draw[dashed] (0,0) -- node[above left]{$r$} (1,0);%
which produces:
I am having difficulty in converting this code into a command that can be placed at arbitrary locations with the radius changed to another value that then updates the dependent values. My attempts do not work when using the \the\numexpr#3/2cm etc and I am not familiar enough with tikz as yet. For instance, when using a simpler sphere code this is how my attempts at making it adaptable to different coordinates worked out:
My use case is to show 4-residue at a time spherical-searches of PDB alpha-carbon files to find helices (if all 4 alpha-carbon points lie in the sphere, high likelihood that it is in a helix region), which looks like this in my main standalone document:
How can I convert the above code into a custom command that can be placed at arbitrary locations and a modifiable radius please? Apologies that this is basic but I have been trying for half an hour and if I am struggling then perhaps others would too, would appreciate a duplicate if so (I have tried searching on here).
\documentclass[border=0pt,tikz]{standalone}
\begin{document}%
\newcommand\drawsphere[3]{%
\draw (-1,0) arc (180:360:1cm and 0.5cm);%
\draw[dashed] (-1,0) arc (180:0:1cm and 0.5cm);%
\draw (0,1) arc (90:270:0.5cm and 1cm);%
\draw[dashed] (0,1) arc (90:-90:0.5cm and 1cm);%
\draw (0,0) circle (1cm);%
\shade[ball color=blue!10!white,opacity=0.40] (0,0) circle (1cm);%
\fill[fill=black] (0,0) circle (1pt);%
\draw[dashed] (0,0) -- node[above left]{$r$} (1,0);%
}%
\begin{tikzpicture}%
\draw (-1,0) arc (180:360:1cm and 0.5cm);%
\draw[dashed] (-1,0) arc (180:0:1cm and 0.5cm);%
\draw (0,1) arc (90:270:0.5cm and 1cm);%
\draw[dashed] (0,1) arc (90:-90:0.5cm and 1cm);%
\draw (0,0) circle (1cm);%
\shade[ball color=blue!10!white,opacity=0.20] (0,0) circle (1cm);%
\fill[fill=black] (0,0) circle (1pt);%
\draw[dashed] (0,0) -- node[above left]{$r$} (1,0);%
\end{tikzpicture}
\end{document}






instead of\newcommand, which you can place like nodes: https://tikz.dev/tikz-pics . Searching forargs` shows you how to pass parameters to a pic. – MS-SPO Aug 30 '23 at 11:32cms but leave the1ptbut also see my comment to Rmano's answer.) – Qrrbrbirlbel Aug 30 '23 at 12:02