# How to draw a circle in 3D such that the plane containing the circle is orthogonal to a given vector?

How do I draw a circle in 3D space such that the plane containing the circle is orthogonal to a given vector?

You can calculate the vector spherical coordinates and then rotate the canvas using TikZ 3d library. I made a simple macro just to show the idea, but you can add more parameters as needed (center, radius, colors, etc.) or make a pic.

\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{3d,perspective}

\newcommand{\mycircle}[3] % vector x, y, z
{%
\pgfmathsetmacro\vtheta{atan2(#2,#1)}                     % spherical coordinate theta
\pgfmathsetmacro\vphi  {acos(#3/sqrt(#1*#1+#2*#2+#3*#3))} % spherical coordinate phi
\begin{scope}[rotate around z=\vtheta,rotate around y=\vphi,canvas is xy plane at z=0]
\draw (-0.5,-0.5) rectangle (0.5,0.5);
\draw[fill=gray,fill opacity=0.2] (0,0) circle (0.5);   % the plane, probably not needed
\end{scope}
}

\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,scale=2,3d view={120}{30}]
\draw[-latex] (0,0,0) -- (1,0,0);
\draw[-latex] (0,0,0) -- (0,1,0);
\draw[-latex] (0,0,0) -- (0,0,1);
\def\vx{0.3}
\def\vy{0.6}
\def\vz{0.9}
\mycircle{\vx}{\vy}{\vz}
\draw[-latex,red] (0,0,0) -- (\vx,\vy,\vz);
\end{tikzpicture}
\end{document}


For a more visual example this is an animation using the same macro.

\documentclass {beamer}
\usepackage    {tikz}
\usetikzlibrary{3d,perspective}

\newcommand{\mycircle}[3] % vector x, y, z
{%
\pgfmathsetmacro\vtheta{atan2(#2,#1)}                     % spherical coordinate theta
\pgfmathsetmacro\vphi  {acos(#3/sqrt(#1*#1+#2*#2+#3*#3))} % spherical coordinate phi
\begin{scope}[overlay,rotate around z=\vtheta,rotate around y=\vphi,canvas is xy plane at z=0]
\draw (-0.5,-0.5) rectangle (0.5,0.5);
\draw[fill=gray,fill opacity=0.2] (0,0) circle (0.5);
\end{scope}
}

\newcommand{\myframe}[3]
{
\begin{frame}\centering
\begin{tikzpicture}[line cap=round,line join=round,thick,scale=6,3d view={120}{30}]
\draw[-latex] (0,0,0) -- (1,0,0);
\draw[-latex] (0,0,0) -- (0,1,0);
\draw[-latex] (0,0,0) -- (0,0,1);
\mycircle{#1}{#2}{#3}
\draw[-latex,red] (0,0,0) -- (#1,#2,#3);
\end{tikzpicture}
\end{frame}
}

\begin{document}
\foreach\i in {0,10,...,80}
{
\pgfmathsetmacro\vx{0.5*cos(\i)}
\pgfmathsetmacro\vy{0.5*sin(\i)}
\pgfmathsetmacro\vz{0}
\myframe{\vx}{\vy}{\vz}
}

\foreach\i in {0,10,...,80}
{
\pgfmathsetmacro\vx{0}
\pgfmathsetmacro\vy{0.5*cos(\i)}
\pgfmathsetmacro\vz{0.5*sin(\i)}
\myframe{\vx}{\vy}{\vz}
}

\foreach\i in {0,10,...,80}
{
\pgfmathsetmacro\vx{0.5*sin(\i)}
\pgfmathsetmacro\vy{0}
\pgfmathsetmacro\vz{0.5*cos(\i)}
\myframe{\vx}{\vy}{\vz}
}
\end{document}


There are infinite circles as you say. In 3D, a circle is defined by a plane and a sphere. In this code, suppose you want to draw a circle with center at (a, b, c), radius rcircle, normal vector of the plane contains the circle is (a,b,c). The circle lies on the sphere with center at (a, b, c) and radius of sphere is rsphere=sqrt(a*a+b*b+c*c+rcircle*rcircle). You can use 3dtools

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{3dtools}% https://github.com/marmotghost/tikz-3dtools
\begin{document}
\begin{tikzpicture}[3d/install view={phi=70,theta=70},line cap=butt,line join=round,declare function={a=2;b=2;c=1;rcircle=4;rsphere=sqrt(a*a+b*b+c*c+rcircle*rcircle);},c/.style={circle,fill,inner sep=1pt}]
\path[overlay]
(a,b,c) coordinate (C)
(0,0,0)  coordinate (O);
\pic[blue]{3d/circle on sphere={R=rsphere,C={(O)}, P={(C)}}};
\path foreach \p/\g in {C/-90,O/90}
{(\p)node[c]{}+(\g:2.5mm) node{$\p$}};
\end{tikzpicture}
\end{document}


3dtools can draw a circumcircle of a triangle. Therefore, if you want ta draw a circle on a plane knowing the given equation, you can choose three non-collinear points lies on this plane. This code draw a circle on the plane has the equation 2 x + 2 y - z = 7

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{3dtools}% https://github.com/marmotghost/tikz-3dtools
\begin{document}
\begin{tikzpicture}[    dot/.style={circle,inner sep=1pt,fill},
3d/install view={phi=100,theta=70}]
\path (2,2,1) coordinate (A)
(4, -1, -1) coordinate (B)
(6, 0, 5) coordinate (C);
\path[draw={none}] pic{3d circle through 3 points={%
A={(A)},B={(B)},C={(C)},center name=I}};
\foreach \p in {A,B,C,I}
\draw[fill=black] (\p) circle (1pt);
\foreach \p/\g in {A/-90,B/-90,I/0,C/90}
\path (\p)+(\g:3mm) node{$\p$};
\end{tikzpicture}
\end{document}


In Asymptote, the built-in routine

circle(C,r,n)


gives the 3D circle with center C, radius r, and normal n.

// Run on http://asymptote.ualberta.ca/
// Use mouse to rotate
unitsize(1cm);                              // choose the unit is cm
triple C=(-1,2,2);                          // center of the circle
real   r=2;                                 // radius of the circle
triple n=(1,2,3);                           // normal of the circle
path3  p=circle(C,r,n);                     // the circle is a 3D path
draw(surface(p),red+opacity(.2));           // filling inside the circle
draw(p,red);                                // draw the circle

draw("$\vec{n}$",align=E,C--C+n,Arrow3);    // showing the normal
dot("$C$",C,red);                           // showing the center
draw(Label("$x$",EndPoint),O--3X);          // the x-axis
draw(Label("$y$",EndPoint),O--5Y);          // the y-axis
draw(Label("$z$",EndPoint),O--5Z);          // the z-axis


I want to draw a circle perpendicular to an vector in 3d. It must be simple. For example, the length of the vector can be the radius, R.

So ... specify the circle center (x0,y0,z0), the unit vector n, and scale it by R.

Can pgfplot do this?

• If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review Sep 5, 2022 at 5:20