# Drawing a circle on non-plane in 3d - Tikz

So I'm trying to draw a circle in a nonstandard plane with TikZ, but can't seem to find any documentation. I originally tried what was found here: Drawing a circle on a non xy-plane with TikZ But this doesn't answer my question as this just changes from one plane to another. Is there any way to construct a 'new plane' to put the circle on?

For example. Say I have 2 vertices (-1,1,3) and (1, -2, 7) which don't live on neither the xy, yz, nor xz planes and I want to construct a circle that is centered at the origin (0,0,0) but on the plane that is constructed by those two points and the origin. (Say with radius 1cm for arbitrary sake)

Is there any way to do this with tikz or are my planes only allowed to live on a canvas?

Notes: I would prefer tikz rather than ps as I do everything else with tikz and this image needs to live inside of a tikz image that is already constructed.

Additionally, here are the libraries I have included:

\usepackage{tikz, tikz-3dplot, pgfplots}
\usetikzlibrary{fit}


Minimal example

\documentclass[12pt]{article}
\usepackage{tikz, tikz-3dplot, pgfplots}
\usetikzlibrary{fit}

\begin{document}
\tdplotsetmaincoords{0}{0}
\begin{tikzpicture}%
%% Coordinate of the vertices:
%%
\coordinate (one) at (-3, -1, 2);
\coordinate (two) at (-3, -2, 1);

%% Planes
\coordinate (O) at (0,0,0);
\coordinate (x) at (1,0,0);
\coordinate (y) at (0,1,0);
\coordinate (z) at (0,0,1);

%% Axes
\draw[->] (O) -- (x) node [right] {$x$};
\draw[->] (O) -- (y) node [right] {$y$};
\draw[->] (O) -- (z) node [right] {$z$};

%% Want a circle on the plane which contains the following two vectors.
\draw[->,thick] (O) -- (one);
\draw[->,thick] (O) -- (two);

\end{tikzpicture}
\end{document}

• Possibly related; tex.stackexchange.com/questions/254820/… Dec 25, 2015 at 1:55
• Please provide a minimum working example. Note, however, that TikZ may not be the best tool for this as it is not really adept at manipulating 3D objects. (Well, it doesn't - you can fake it at best.)
– cfr
Dec 25, 2015 at 2:07
• @cfr It's hard to ask for a minimum working example when my question is about asking for a minimum working example... I tried to give as best of an example as I could. Dec 25, 2015 at 3:56
• @JohnKormylo The tdplot_rotated_coords might be what I'm looking for. I'll test them out and see. Thanks for the link. Dec 25, 2015 at 3:57
• You can provide the code for the vertices so that people don't have to recreate your framework from scratch but can copy the bit you've already got and just focus on the bit you need help with. Right now, anybody who wants to help has to create a document from scratch. You should post the document for the vertices and not just a fragment. Then people can copy-paste-compile and get to the interesting/difficult bit right away. People like puzzles. Setting them up is boring, though.
– cfr
Dec 25, 2015 at 4:13

So, you'll need a bit of math.

Let's first find out the expression of your rotated frame in the reference frame. I'll assume (one) is the rotated x (you'll have to normalize it). For the sake of clarity, I'll assume

\coordinate(one) at (1/2, 1/2, -{1/\sqrt(2)})
\coordinate(two) at (1/2, 1/2,  {1/\sqrt(2)})


and you obtain the third vector of the rotated frame as the cross product of the two first:

\coordinate(three) at (-{1/\sqrt(2)}, {1/\sqrt(2)}, 0)


This gives you the rotation matrix from the rotated frame into the reference frame as:

1/2        1/2        -{1/\sqrt(2)}
1/2        1/2         {1/\sqrt(2)}
{1/\sqrt(2)} {1/\sqrt(2)}  0


The rotation matrix from the reference frame to the rotation frame is its transpose:

1/2         1/2         {1/\sqrt(2)}
1/2         1/2         {1/\sqrt(2)}
-{1/\sqrt(2)} {1/\sqrt(2)}  0


So that (following for example Diebel, 2006, Representing attitude: Euler angles, Unit Quaternions and Rotation Vectors. Furthermore, I've made a little mistake, tikz-3dplot assumes zyz Euler convention, while Diebel in 5.5.3 which I use, assume zxz. But anyway, seems to work in that special case ^^) you have the three angles of the Euler sequence as

\phi = atan2(r13, r23)
\theta = acos(r33)
\psi = atan2(r31, -r32)


which gives in our example:

\phi = -45
\theta = 90
\psi = 135


(Please, I may have done a dumb mistake in the angle evaluation since in my reasoning, signs on phi and psi are swapped) So, updating your code, with the use of tdplot_rotated_coords, we obtain:

(Notice the addition of tdplot_main_coords to your tikzpicture, your \tdplotsetmaincoords was ineffective)

\documentclass{standalone}
\usepackage{tikz, tikz-3dplot}
\usetikzlibrary{calc}

\begin{document}
\tdplotsetmaincoords{50}{30}
\begin{tikzpicture}[tdplot_main_coords]%
%% Coordinate of the vertices:
%%
\coordinate (one) at (1/2, 1/2, {1/sqrt(2)});
\coordinate (two) at (1/2, 1/2, -{1/sqrt(2)});
\coordinate (three) at (-{1/sqrt(2)}, {1/sqrt(2)}, 0);

%% Planes
\coordinate (O) at (0,0,0);
\coordinate (x) at (1,0,0);
\coordinate (y) at (0,1,0);
\coordinate (z) at (0,0,1);

%% Axes
\draw[->] (O) -- (x) node [right] {$x$};
\draw[->] (O) -- (y) node [right] {$y$};
\draw[->] (O) -- (z) node [right] {$z$};

%% Want a circle on the plane which contains the following two vectors.
\draw[->,thick] (O) -- (one);
\draw[->,thick] (O) -- (two);
\draw[->,thick] (O) -- (three);

\tdplotsetrotatedcoords{-45}{90}{135}
\begin{scope}[tdplot_rotated_coords]
\draw (0,0,0) circle (1);
\end{scope}

\end{tikzpicture}
\end{document}