[Tex/LaTex] Drawing a circle on non-plane in 3d – Tikz

circlestikz-3dplottikz-pgf

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}

But am willing to add additional libraries as needed.
Thanks.


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}

Best Answer

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}

The result