4

I have this steel plate, and I want to put a circle on it so that the circle lies in the "horizontal" plane of the plate:

% vim: ft=tex
\RequirePackage{luatex85,shellesc}
\documentclass[tikz]{standalone}

\usepackage{listings}

%% e-TeX tools
\usepackage{etoolbox}

%% Colours - put this before typography so additional named colours can be defined.
\usepackage{xcolor}
\definecolor{red}{HTML}{DC291E}
\definecolor{blue}{HTML}{04588A}
\definecolor{orange}{HTML}{FA6B00}
\colorlet{steel}{blue!20!gray}

%% Typography Settings
\usepackage{fontspec}
\usepackage{xunicode}

%% Maths typography — re-enable these if we need maths support
\usepackage{physics}
\usepackage{mathtools}
\usepackage{unicode-math}

%% Main Font list
%%%%
%
% The TeX Gyre family of fonts should come preinstalled with TeX Live, but they
% are also available from here:
% http://www.gust.org.pl/projects/e-foundry/tex-gyre/
%
%%%%
\setmainfont{TeX Gyre Pagella}
\setmathfont{TeX Gyre Pagella Math}

\usepackage{standalone}
\usepackage{tikz}

% Lua math library
\usepgflibrary{luamath}
\pgfkeys{pgf/luamath=parser}

\usetikzlibrary{calc}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{decorations.shapes}
\usetikzlibrary{intersections}
\usetikzlibrary{positioning}
% \usetikzlibrary{external}
\usetikzlibrary{patterns}
\usepgflibrary{arrows.meta}
\usetikzlibrary{bending}

% \tikzexternalize[prefix=tikz/,shell escape=-enable-write18]
% \tikzset{external/system call={lualatex \tikzexternalcheckshellescape -halt-on-error -interaction=batchmode -jobname "\image" "\texsource"}}
% \tikzset{
%   % Defines a custom style which generates BOTH, .pdf and .png export
%   % but prefers the .png on inclusion.
%   %
%   % This style is not pre-defined, you may need to copy-paste and
%   % adjust it.
%   png export/.style={%
%     external/system call/.add=%
%       {}
%       ; convert -density 300 -transparent white "\image.pdf" "\image.png",
%     % Don't need this as we're keeping the PDF in the document
%     % /pgf/images/external info,
%     % /pgf/images/include external/.code={%
%     %   \includegraphics
%     %   [width=\pgfexternalwidth,height=\pgfexternalheight]
%     %   {##1.png}%
%     % },
%   }
% }

\usepackage{siunitx}
\sisetup{detect-all, per-mode=symbol}
\DeclareSIPostPower\fourth{4}

\DeclareGraphicsExtensions{.pdf,.png,.jpg}

%% Define all TikZ styles here
\tikzset{%
  view top right/.style={
    x={(0.866cm,0.5cm)},
    y={(0,1cm)},
    z={(-0.939cm,0.342cm)}
  },
  % png export,
}

\begin{document}
\begin{tikzpicture}[view top right]

    \coordinate (front-bottom-right) at (0, 0, 0);
    \coordinate (front-bottom-left) at (0, 0, 3);
    \coordinate (back-bottom-left) at (3, 0, 3);
    \coordinate (back-bottom-right) at (3, 0, 0);
    \coordinate (front-top-right) at (0, 1, 0);
    \coordinate (front-top-left) at (0, 1, 3);
    \coordinate (back-top-right) at (3, 1, 0);
    \coordinate (back-top-left) at (3, 1, 3);

    \fill [steel!50!white]
      (front-bottom-right)
      -- (front-bottom-left)
      -- (front-top-left)
      -- (front-top-right)
      -- cycle;

    \fill [steel!62.5!white]
      (front-bottom-right)
      -- (back-bottom-right)
      -- (back-top-right)
      -- (front-top-right)
      -- cycle;

    \fill [steel!37.5!white]
      (front-top-right)
      -- (front-top-left)
      -- (back-top-left)
      -- (back-top-right)
      -- cycle;

    \draw [steel!75!black]
      (back-top-left)
      -- (front-top-left)
      -- (front-bottom-left)
      -- (front-bottom-right)
      -- (back-bottom-right)
      -- (back-top-right)
      -- cycle;

    \draw [steel!20!white]
      (front-top-left)
      -- (front-top-right)
      -- (back-top-right)
      (front-top-right)
      -- (front-bottom-right);

    % HELP?
    \draw [line width=1.5pt] (1.5, 1, 1.5) circle [radius=1];

  \end{tikzpicture}
\end{document}

A few older questions seem to offer partial solutions, but many make mention of a 3d library that is not mentioned in the current manual, though does exist on my system. Whilst I could draw it manually with lots of trial and effort, I'd prefer to figure out a way that I could adapt for future drawings with ease.

10

You don't really need anything fancy to draw circles (or ellipses) in the coordinate planes, as you can define a coordinate system for the circle itself. By default it is drawn in the xy plane, but you can specify, e.g., [x={(0,0,1)}] before drawing the circle to locally replace x with z and draw it in the zy plane instead.

\documentclass[tikz]{standalone}
\definecolor{blue}{HTML}{04588A}
\colorlet{steel}{blue!20!gray}

\tikzset{%
  view top right/.style={
    x={(0.866cm,0.5cm)},
    y={(0,1cm)},
    z={(-0.939cm,0.342cm)}
  },
}

\begin{document}
\begin{tikzpicture}[view top right]
    \coordinate (front-bottom-right) at (0, 0, 0);
    \coordinate (front-bottom-left) at (0, 0, 3);
    \coordinate (back-bottom-left) at (3, 0, 3);
    \coordinate (back-bottom-right) at (3, 0, 0);
    \coordinate (front-top-right) at (0, 1, 0);
    \coordinate (front-top-left) at (0, 1, 3);
    \coordinate (back-top-right) at (3, 1, 0);
    \coordinate (back-top-left) at (3, 1, 3);

    \fill [steel!50!white]
      (front-bottom-right) -- (front-bottom-left)
      -- (front-top-left) -- (front-top-right)
      -- cycle;

    \fill [steel!62.5!white]
      (front-bottom-right) -- (back-bottom-right)
      -- (back-top-right) -- (front-top-right)
      -- cycle;

    \fill [steel!37.5!white]
      (front-top-right) -- (front-top-left)
      -- (back-top-left) -- (back-top-right)
      -- cycle;

    \draw [steel!75!black]
      (back-top-left) -- (front-top-left) -- (front-bottom-left)
      -- (front-bottom-right) -- (back-bottom-right) -- (back-top-right)
      -- cycle;

    \draw [steel!20!white]
      (front-top-left) -- (front-top-right) -- (back-top-right)
      (front-top-right) -- (front-bottom-right);

    \draw[thick] (1.5,.5,0) circle (1.5 and .5);
    \draw[thick, red] (1.5, 1, 1.5) [y={(0,0,1)}] circle (1.5);
    \draw[thick, blue] (0,.5,1.5) [x={(0,0,1)}] circle (1.5 and .5);
  \end{tikzpicture}
\end{document}

circles on a cuboid

  • Note that this should also work for drawing circles in other planes given an orthonormal basis for the plane, but you'll probably want to name your basis coordinates before using them. Because the two coordinates are changed sequentially, after you assign the first basis vector the coordinate system for the second will no longer be the original one. – Emma Oct 18 '16 at 17:39
  • Oh thanks. It's so obvious now that you've pointed it out, and yet I couldn't decipher it last night. May I ask why you put all the drawing within a scope rather than just set the view top right on the picture environment? – Robbie Oct 19 '16 at 6:26
  • Oops, that's a relic from the problem-solving phase when I was comparing the transformed and untransformed circles. Fixed now! – Emma Oct 19 '16 at 12:38
  • Ah right. I thought maybe I wasn't using very good syntax in my drawings, but if they're different ways of doing the same thing then that's ok. I have an unfortunate habit of occasionally accidentally discovering bugs by using syntax unexpected by the authors :/ – Robbie Oct 19 '16 at 13:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.