我在倾斜平面上投影文本时遇到了困难。更准确地说,我想用 latex 解决以下问题。
练习:下图中,我们看到了一个截角立方体的两个不同视图,该立方体有 14 个数字面。与有 13 个数字的面相对的面上的数字是多少?
左边的图是我在 TikZ 中做的,我用 xslant、yslant 和 rotation 把数字放在图上。但最终的结果并不令人满意,而且确定 xslan、yslant 和 rotation 命令的参数非常费力,而且有些随意。我输入的代码和得到的图是这些。
\documentclass[]{article}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{75}{105}
\centerline{
\begin{tikzpicture} [tdplot_main_coords]
\def\a{1.1}; %-- half of the edge of the cube
%-----faces with 4 edges ----------------------------------
\draw[-] (\a,0,2*\a) -- (2*\a,\a,2*\a) -- (\a,2*\a,2*\a) -- (0,\a,2*\a) -- cycle;
\draw[-] (2*\a,0,\a) -- (2*\a,\a,0) -- (2*\a,2*\a,\a) -- (2*\a,\a,2*\a) -- cycle;
\draw[-] (\a,2*\a,2*\a) -- (2*\a,2*\a,\a) -- (\a,2*\a,0) -- (0,2*\a,\a) -- cycle;
%----- others edges -------
\draw[-] (\a,0,2*\a) -- (2*\a,0,\a) -- (\a,0,0) -- (2*\a,\a,0) -- (\a,2*\a,0);
%---nodes --------------------
\node[xslant=0.5,yslant=-0.1,rotate=-10] at (\a,\a,2*\a) {\large{14}};
\node[xslant=0.5,yslant=-0.1,rotate=-5] at (1.5*\a,0.3*\a,1.7*\a) {\large{4}};
\node[xslant=0.1,rotate=1] at (2*\a,\a,\a) {\large{13}};
\node[xslant=-0.5,yslant=0.1] at (1.7*\a,1.7*\a,1.7*\a) {\large{1}};
\node[xslant=-0.6,yslant=0.6,rotate=10] at (\a,2*\a,\a) {\large{10}};
\node[xslant=0.5,yslant=-0.1,rotate=23] at (1.7*\a,0.3*\a,0.3*\a) {\large{3}};
\node[xslant=0.5,yslant=-0.1] at (1.7*\a,1.7*\a,0.4*\a) {\large{8}};
\end{tikzpicture}}
\end{document}
我读了一些关于平行于坐标平面的平面投影的文章。例如,我发现了类似主题。但是,这些文章中都没有使用 \ tdplotsetmaincoords 命令。此外,我找不到有关在任意平面上投影文本的参考资料。我想请大家帮忙制作截断数值立方体所需的图形。非常感谢。
答案1
为了得到更好的图形,我使用了节点命令中的倾斜选项,以便能够写入与某个线段相切的文本。例如,为了将数字 14 放在第一个图形的顶面上,我使用了
\path (A) -- node[sloped] {14} (C);
其中 (A) 和 (C) 是此面的相对顶点。我对节点命令中的倾斜选项一无所知。我是在阅读中了解到这一点的这个话题。
为了得到第二个图形的顶点坐标,我旋转了第一个图形截角立方体的顶点。我读了这篇文章后学到了这一点这个话题。
我使用 xslant、yslant 和旋转手动调整了每个面上每个数字的位置。调整这些数字非常困难,我相信应该有更自动化的方法将数字投射到截角立方体的面上。
我发现另一个话题金字塔的一个漂亮例子,金字塔表面有文字。不幸的是,这个例子在 PSTricks 中,而我没有足够的知识来理解该代码。
我的 tex 代码和截角立方体(带编号面)的结果如下。虽然不是 100%,但或多或少是可以接受的。这个答案并没有结束这个话题的讨论,因为肯定有更好的解决方案。
\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{arrows}
\usepackage{amsmath}
\begin{document}
\newcommand{\rotateRPY}[3]% roll, pitch, yaw
{ \pgfmathsetmacro{\rollangle}{#1}
\pgfmathsetmacro{\pitchangle}{#2}
\pgfmathsetmacro{\yawangle}{#3}
% to what vector is the x unit vector transformed, and which 2D vector is this?
\pgfmathsetmacro{\newxx}{cos(\yawangle)*cos(\pitchangle)}
\pgfmathsetmacro{\newxy}{sin(\yawangle)*cos(\pitchangle)}
\pgfmathsetmacro{\newxz}{-sin(\pitchangle)}
\path (\newxx,\newxy,\newxz);
\pgfgetlastxy{\nxx}{\nxy};
% to what vector is the y unit vector transformed, and which 2D vector is this?
\pgfmathsetmacro{\newyx}{cos(\yawangle)*sin(\pitchangle)*sin(\rollangle)-sin(\yawangle)*cos(\rollangle)}
\pgfmathsetmacro{\newyy}{sin(\yawangle)*sin(\pitchangle)*sin(\rollangle)+ cos(\yawangle)*cos(\rollangle)}
\pgfmathsetmacro{\newyz}{cos(\pitchangle)*sin(\rollangle)}
\path (\newyx,\newyy,\newyz);
\pgfgetlastxy{\nyx}{\nyy};
% to what vector is the z unit vector transformed, and which 2D vector is this?
\pgfmathsetmacro{\newzx}{cos(\yawangle)*sin(\pitchangle)*cos(\rollangle)+ sin(\yawangle)*sin(\rollangle)}
\pgfmathsetmacro{\newzy}{sin(\yawangle)*sin(\pitchangle)*cos(\rollangle)-cos(\yawangle)*sin(\rollangle)}
\pgfmathsetmacro{\newzz}{cos(\pitchangle)*cos(\rollangle)}
\path (\newzx,\newzy,\newzz);
\pgfgetlastxy{\nzx}{\nzy};
}
\tikzset{RPY/.style={x={(\nxx,\nxy)},y={(\nyx,\nyy)},z={(\nzx,\nzy)}}}
\tdplotsetmaincoords{75}{105}
\centerline{
\begin{tikzpicture} [tdplot_main_coords]
\def\a{1.1}; %-- half of the edge of the cube
\coordinate (A) at (\a,0,2*\a);
\coordinate (B) at (2*\a,\a,2*\a);
\coordinate (C) at (\a,2*\a,2*\a);
\coordinate (D) at (0,\a,2*\a);
\coordinate (E) at (2*\a,0,\a);
\coordinate (F) at (2*\a,\a,0);
\coordinate (G) at (2*\a,2*\a,\a);
\coordinate (H) at (\a,2*\a,0);
\coordinate (I) at (0,2*\a,\a);
\coordinate (J) at (\a,0,0);
%----- triangular faces of the first figure -------
\draw[fill=lightgray!3!white,draw=none] (E) -- (A) -- (B) -- cycle;
\draw[fill=lightgray!3!white,draw=none] (B) -- (C) -- (G) -- cycle;
\draw[fill=lightgray!3!white,draw=none] (F) -- (G) -- (H) -- cycle;
\draw[fill=lightgray!3!white,draw=none] (E) -- (F) -- (J) -- cycle;
%-----faces with 4 edges ----------------------------------
\draw[fill=lightgray!2!white,draw=black,thick] (A) -- (B) -- (C) -- (D) -- cycle;
\draw[fill=lightgray!2!white,draw=black,thick] (E) -- (F) -- (G) -- (B) -- cycle;
\draw[fill=lightgray!2!white,draw=black,thick] (C) -- (G) -- (H) -- (I) -- cycle;
%----- others edges -------
\draw[-,thick] (A) -- (E) -- (J) -- (F) -- (H);
%---nodes --------------------
\path (A) -- node[sloped,xslant=.6,yscale=0.9,xscale=1.1] {\large{\bf{14}}} (C);
\node[xslant=-0.5,yslant=0.2,scale=1.1] at (1.7*\a,1.7*\a,1.65*\a) {\large{\bf{1}}};
\node[xslant=0.5,yslant=-0.1,scale=1.05] at (1.7*\a,1.7*\a,0.4*\a) {\large{\bf{8}}};
\path ($(\a,0,2*\a)!0.3!(2*\a,0,\a)$) -- node[sloped,xslant=.2,yscale=1.2] {\large{\bf{4}}} ($(2*\a,\a,2*\a)!0.3!(2*\a,0,\a)$);
\path (2*\a,0,\a) -- node[sloped,xslant=-0.07,yscale=1.3,xscale=1.2] {\large{\bf{13}}} (2*\a,2*\a,\a);
\path (2*\a,2*\a,\a) -- node[sloped,xslant=0.5] {\large{\bf{10}}} (0,2*\a,\a);
\path ($(\a,0,0)!0.3!(2*\a,0,\a)$) -- node[sloped,xslant=-0.4,rotate=12,xshift=-2pt,yscale=0.8] {\large{\bf{3}}}
($(2*\a,\a,0)!0.3!(2*\a,0,\a)$);
\end{tikzpicture} \ \ \ \ \ \
%--- SECOND FIGURE (on the right)
\tdplotsetmaincoords{75}{105}
\begin{tikzpicture} [tdplot_main_coords]
\def\a{1.05}; %-- half of the edge of the cube
\rotateRPY{-40}{-39}{15}
\begin{scope}[RPY]
\coordinate (A) at (2*\a,0,\a);
\coordinate (B) at (2*\a,\a,0);
\coordinate (C) at (2*\a,2*\a,\a);
\coordinate (D) at (2*\a,\a,2*\a);
\coordinate (E) at (\a,2*\a,2*\a);
\coordinate (F) at (\a,2*\a,0);
\coordinate (G) at (0,2*\a,\a);
\coordinate (H) at (\a,0,0);
\coordinate (I) at (0,\a,0);
\coordinate (J) at (\a,0,2*\a);
%----- triangular faces of the second figure -------
\draw[fill=lightgray!3!white,draw=none] (A) -- (J) -- (D) -- cycle;
\draw[fill=lightgray!3!white,draw=none] (D) -- (E) -- (C) -- cycle;
\draw[fill=lightgray!3!white,draw=none] (C) -- (F) -- (B) -- cycle;
\draw[fill=lightgray!3!white,draw=none] (A) -- (B) -- (H) -- cycle;
%-----faces with 4 edges ----------------------------------
\draw[fill=lightgray!2!white,draw=black,thick] (A) -- (B) -- (C) -- (D) -- cycle;
\draw[fill=lightgray!2!white,draw=black,thick] (E) -- (C) -- (F) -- (G) -- cycle;
\draw[fill=lightgray!2!white,draw=black,thick] (H) -- (B) -- (F) -- (I) -- cycle;
%---- other edges
\draw[-,black,thick] (H) -- (A) -- (J) -- (D) -- (E);
%---nodes --------------------
\path ($(A)!0.5!(B)$) -- node[sloped,xslant=0.02,yscale=1.3,xscale=1.2] {\large{\bf{11}}} ($(D)!0.5!(C)$);
\path (H) -- node[sloped,xslant=0.2,rotate=-10,xscale=1.1,yscale=1.2] {\large{\bf{7}}} (F);
\path (C) -- node[sloped,yslant=-0.35,xslant=-0.1,rotate=-5,yshift=1pt] {\large{\bf{12}}} (G);
\path (A) -- node[sloped,xslant=-0.1,yslant=0.1,xshift=-8pt,yshift=1pt, rotate=26,yscale=1.4,xscale=1.1] {\large{\bf{3}}} ($(H)!0.5!(B)$);
\path ($(B)!0.4!(F)$) -- node[sloped,xslant=0.1,yscale=1.25,xscale=1.2,yshift=1pt] {\large{\bf{2}}} ($(C)!0.4!(F)$);
\path ($(E)!0.6!(D)$) -- node[sloped,xslant=0.3,rotate=5,yscale=1.3,xscale=1.1,xshift=2pt] {\large{\bf{5}}} ($(E)!0.6!(C)$);
\path ($(J)!0.5!(A)$) -- node[sloped,xslant=-0.4,xscale=1.1,yscale=0.6] {\bf{8}} ($(J)!0.5!(D)$);
\end{scope}
\end{tikzpicture}}
\end{document}