![在 3D 平面上绘制圆圈](https://linux22.com/image/342731/%E5%9C%A8%203D%20%E5%B9%B3%E9%9D%A2%E4%B8%8A%E7%BB%98%E5%88%B6%E5%9C%86%E5%9C%88.png)
我有这块钢板,我想在上面画一个圆圈,使圆圈位于钢板的“水平”平面上:
% 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很少 较旧 问题似乎提供部分的解决方案,但很多都提到了3d
当前手册中未提及的库,尽管我的系统上确实存在。虽然我可以通过大量的尝试和努力手动绘制它,但我更愿意找出一种可以轻松适应未来绘图的方法。
答案1
您实际上不需要任何花哨的东西就可以在坐标平面上绘制圆形(或椭圆形),因为您可以为圆形本身定义一个坐标系。默认情况下,它绘制在 xy 平面中,但您可以在[x={(0,0,1)}]
绘制圆形之前指定将 x 局部替换为 z,然后在 zy 平面中绘制它。
\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}