# How to rotate a circle around two axes?

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:

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?

• Welcome! Take a look at tikz-3dplot but note that TikZ is not the ideal choice for 3D. (It is OK for simple stuff like this, but if you need significant 3D stuff, better choose a tool designed for the job.)
– cfr
Jun 6, 2016 at 13:05
• Jun 6, 2016 at 17:03
• @cfr any advices on such designed 3D tool?
– s.k
Sep 3, 2020 at 10:07

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}


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}


• @Louis If it answered your question, you should consider accepting it by clicking the greyed out tick at the top left of the answer. But only if it did answer the question, of course.
– cfr
Jun 20, 2016 at 21:28
• Is there a way to draw the circle, or even an arc, around the y-axis? Per default arcs and circles are drawn around the z-axis (in the xy-plane).
– Matt
May 1, 2020 at 4:20