# tikz-3dplot: How to draw small circles of a sphere in a given angle?

What is the right method to draw a small circle at a certain angle?

I can only do it improvisational for the right angle.

Hint: I want to draw such a picture:

\documentclass[margin=5mm, tikz]{standalone}
\usepackage{amsmath, amsfonts}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{arrows,calc,backgrounds}
\begin{document}

\pgfmathsetmacro{\r}{2.6} %

\tdplotsetmaincoords{60}{110}
\begin{tikzpicture}[
tdplot_main_coords,
%tdplot_rotated_coords,
font=\footnotesize,
Helpcircle/.style={gray!70!black,
%densely dashed
},
]

\pgfmathsetmacro{\h}{0.9*\r} %
\coordinate[label=$M$] (M) at (0,0,0);
\coordinate[label=$S$] (S) at (0,0,\h);

\draw[Helpcircle, rotate=90, red] (0,0,-\h) coordinate[label=$A$] (A) circle[radius=sqrt(\r^2-\h^2)];
\draw[] (M) -- (A);

\pgfmathsetmacro{\teta}{30} %
\pgfmathsetmacro{\y}{-\h*cos(\teta)} %
\draw[blue] (M) -- ([xshift=\r cm, yshift=\y cm]M);

% Sphere
\begin{scope}[tdplot_screen_coords, on background layer]
\fill[ball color= gray!20, opacity = 0.25] (M) circle (\r);
\end{scope}

%% Points
\foreach \P in {M,S, A}{
}

\begin{scope}[-latex, shift={(M)}, xshift=1.5*\r cm, yshift=0.1*\r cm]
\foreach \P/\s/\Pos in {(1,0,0)/x/right, (0,1,0)/y/below, (0,0,1)/z/right}
\draw[] (0,0,0) -- \P node[\Pos, pos=0.9,inner sep=2pt]{$\s$};
\end{scope}

\end{tikzpicture}
\end{document}

• The blue line was drawn using screen coordinates (xshift,yshift), as was coordinate (A) [rotate]. You can translate 3D coordinates into screen coordinate, but not the inverse. Jul 24, 2019 at 15:58
• tikz-3dplot autoloads the 3d (and calc) libraries. You can switch to specific plane using e.g. canvas is xz plane at y=1.
– user121799
Jul 25, 2019 at 1:43

This shows how to draw the circle at (A) using 3D coordinates, assuming you intended (A) to be at (0,\h,0).

Using rotated coordinates can be tricky. The first angle rotates the XY plane, and has no effect on the Z axis. The second angle rotates in the (new) XZ plane, and has no effect on the (new) Y axis. Try to avoid using the third angle, which rotates in the new XY plane, although some transformations can only be done that way; e.g. \tdplotsetrotatedcoords{90}{90}{-90}.

Note that the transformations are NOT cumulative.

BTW, \r^2 is computed using exp(2*log(\r)) which is slow and only works for positive numbers.

\documentclass[margin=5mm, tikz]{standalone}
\usepackage{amsmath, amsfonts}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{arrows,calc,backgrounds}
\begin{document}

\pgfmathsetmacro{\r}{2.6} %

\tdplotsetmaincoords{60}{110}
\begin{tikzpicture}[
tdplot_main_coords,
%tdplot_rotated_coords,
font=\footnotesize,
Helpcircle/.style={gray!70!black,
%densely dashed
},
]

\pgfmathsetmacro{\h}{0.9*\r} %
\coordinate[label=$M$] (M) at (0,0,0);
\coordinate[label=$S$] (S) at (0,0,\h);
\coordinate[label=$A$] (A) at (0,\h,0);

\draw[Helpcircle] (S) circle[radius=sqrt(\r*\r-\h*\h)];% much faster then ^2

\tdplotsetrotatedcoords{90}{90}{0}%
\draw[] (M) -- (A);

% Sphere
\begin{scope}[tdplot_screen_coords, on background layer]
\fill[ball color= gray!20, opacity = 0.25] (M) circle (\r);
\end{scope}

%% Points
\foreach \P in {M,S, A}{
}

\begin{scope}[-latex, shift={(M)}, xshift=1.5*\r cm, yshift=0.1*\r cm]
\foreach \P/\s/\Pos in {(1,0,0)/x/right, (0,1,0)/y/below, (0,0,1)/z/right}
\draw[] (0,0,0) -- \P node[\Pos, pos=0.9,inner sep=2pt]{$\s$};
\end{scope}

\end{tikzpicture}
\end{document}