[Tex/LaTex] How to rotate a circle around two axes

3dtikz-3dplottikz-pgf

I am trying to rotate a circle around two axes.
The circle should be placed perpendicular to the red vector.

Code:

\documentclass[a4paper]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
    % xyz axes
    \draw[thick,->] (0,0,0) -- (5,0,0) node[anchor=north east]{$x$};
    \draw[thick,->] (0,0,0) -- (0,5,0) node[anchor=north west]{$y$};
    \draw[thick,->] (0,0,0) -- (0,0,5) node[anchor=north west]{$z$};
    % vector
    \draw[->,red] (0,0,0) -- (4,4,4);
    % center of circle
    \fill (3,3,3) circle (1pt);
    % circle
    \draw (3,3,3) circle (3); % rotation?
\end{tikzpicture}
\end{document}

Output:

example picture

I would like to know how to rotate the circle in a way that the red vector and the circle are perpendicular to each other.
I think it's a 45° rotation around the y-axis and 45° around the z-axis but how is this realizable using tikz?

Best Answer

I'd suggest using tikz-3dplot if you really want to use TikZ since it will handle many of the calculations required to fake 3D with a package designed to draw in 2D.

For example:

\documentclass[tikz,border=10pt,multi]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{70}{110}
\tdplotsetrotatedcoords{180}{-90}{-90}
\begin{tikzpicture}[tdplot_main_coords]
  \begin{scope}[tdplot_rotated_coords]
    \draw[thick,->] (0,0,0) -- (5,0,0) node[anchor=north east]{$x$};
    \draw[thick,->] (0,0,0) -- (0,5,0) node[anchor=north west]{$y$};
    \draw[thick,->] (0,0,0) -- (0,0,5) node[anchor=north west]{$z$};
    \draw[->,red] (0,0,0) -- (4,4,4);
    \path [fill] (3,3,3) coordinate (c) circle (1pt);
    \tdplotdrawarc[tdplot_rotated_coords]{(c)}{3}{0}{360}{}{}
  \end{scope}
\end{tikzpicture}
\end{document}

circle in 3D

If we wanted to shade the circle to give more of a sense of depth, we could use the backgrounds library and some care about the drawing order. For example:

\documentclass[tikz,border=10pt,multi]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{backgrounds}
\begin{document}
\tdplotsetmaincoords{70}{110}
\tdplotsetrotatedcoords{180}{-90}{-90}
\begin{tikzpicture}[tdplot_main_coords]
  \begin{scope}[tdplot_rotated_coords]
    \draw[thick,->] (0,0,0) coordinate (o) -- (5,0,0) node[anchor=north east]{$x$};
    \draw[thick,->] (o) -- (0,5,0) node[anchor=north west]{$y$};
    \draw[thick,->] (o) -- (0,0,5) node[anchor=north west]{$z$};
    \draw[red] (o) -- (3,3,3) coordinate (c);
    \path [fill] (c) circle (1pt);
    \begin{scope}[on background layer]
      \draw[->,red] (c) -- (4,4,4);
      \tdplotdrawarc[tdplot_rotated_coords, right color=blue!50!cyan, left color=blue!50!cyan!15!white, fill opacity=.25, postaction={top color=blue!50!cyan!15!white, bottom color=blue!50!cyan, fill opacity=.25}]{(c)}{3}{0}{360}{}{}
    \end{scope}
  \end{scope}
\end{tikzpicture}
\end{document}

shaded version