作为项目的一部分,我想要:
- 绘制一个方形金字塔,可通过变量“宽度”、“高度”和“深度”轻松修改,有点像长方体的创作。
- 用虚线画出背部线条
i | 金字塔的尖端应该居中
我已经这样做了:
\documentclass[border=10pt, multi, tikz]{standalone}
\usetikzlibrary{quotes,arrows.meta}
\tikzset{
%\tikzset{%
%}
pyramidoid/.pic={
\draw [
style={pic actions, solid, opacity=.5}, pic actions]
(0,0,0) coordinate (o) -- ++(-\pyrscale*\pyrx,0,0) coordinate (a) edge coordinate [pos=1] (d) ++(0,0,-\pyrscale*\pyrz) -- ++(0,\pyrscale*\pyrz,0) coordinate (b) -- cycle
(o) -- (0, 0, -\pyrscale*\pyrz) coordinate (c) edge (d) -- (b) edge (d) -- cycle
;
},
width/.store in=\pyrx,
height/.store in=\pyry,
depth/.store in=\pyrz,
units/.store in=\pyrunits,
scale/.store in=\pyrscale,
width=10,
height=10,
depth=10,
units=cm,
scale=.2,
}
\begin{document}
\begin{tikzpicture}
%\pic {pyramidoid};
\pic {pyramidoid={width=10, height=20, depth=10}};% Pyramide en PC (perspective cavalière)
\end{tikzpicture}
\end{document}
但我不知道这是否是正确的方法,因为我最近开始学习 LaTex......
长方体图示例:
\documentclass[border=10pt, multi, tikz]{standalone}
\usetikzlibrary{quotes,arrows.meta}
\tikzset{
annotated cuboid/.pic={
\tikzset{%
every edge quotes/.append style={midway, auto},
/cuboid/.cd,
#1
}
\draw [every edge/.append style={pic actions, densely dashed, opacity=.5}, pic actions]
(0,0,0) coordinate (o) -- ++(-\cubescale*\cubex,0,0) coordinate (a) -- ++(0,-\cubescale*\cubey,0) coordinate (b) edge coordinate [pos=1] (g) ++(0,0,-\cubescale*\cubez) -- ++(\cubescale*\cubex,0,0) coordinate (c) -- cycle
(o) -- ++(0,0,-\cubescale*\cubez) coordinate (d) -- ++(0,-\cubescale*\cubey,0) coordinate (e) edge (g) -- (c) -- cycle
(o) -- (a) -- ++(0,0,-\cubescale*\cubez) coordinate (f) edge (g) -- (d) -- cycle;
;
},
/cuboid/.search also={/tikz},
/cuboid/.cd,
width/.store in=\cubex,
height/.store in=\cubey,
depth/.store in=\cubez,
units/.store in=\cubeunits,
scale/.store in=\cubescale,
width=10,
height=10,
depth=10,
units=cm,
scale=.2,
}
\begin{document}
\begin{tikzpicture}
\pic {annotated cuboid};% cube en PC (perspective cavalière)
%\pic {annotated cuboid={width=20, height=5, depth=10}};
%\pic {annotated cuboid={width=10, height=20, depth=10}};
\end{tikzpicture}
\end{document}
答案1
这会在“斜投影”中绘制一个金字塔,非常感谢您的翻译!您的方法总体来说很棒,但为了名称空间,我会以略有不同的方式使用 pgf 键,并将它们存储在目录下pyramidoid
。
\documentclass[border=10pt, multi, tikz]{standalone}
\tikzset{pics/pyramidoid/.style={code={
\tikzset{pyramidoid/.cd,#1}
\def\pv##1{\pgfkeysvalueof{/tikz/pyramidoid/##1}}
\draw [solid, opacity=.5, pic actions]
(0,0,0) coordinate (o)
(-\pv{scale}*\pv{width},0,0) coordinate (a)
(-\pv{scale}*\pv{width},\pv{scale}*\pv{depth},0) coordinate (b)
(0,\pv{scale}*\pv{depth},0) coordinate (c)
(-\pv{scale}*\pv{width}/2,\pv{scale}*\pv{depth}/2,\pv{scale}*\pv{height}) coordinate (d)
(b) edge[densely dashed] (a)
edge[densely dashed] (c) edge[densely dashed] (d)
(o) -- (a) -- (d) -- (o) -- (c) -- (d) ;
}},
pyramidoid/.cd,
width/.initial=10,
height/.initial=5,
depth/.initial=10,
scale/.initial=.2,
}
\begin{document}
\begin{tikzpicture}[x={(1cm,0cm)},y={(30:1cm)},z={(0cm,1cm)},line cap=round,line join=round]
\pic {pyramidoid={width=10, height=20, depth=10}};% Pyramide en PC (perspective cavalière)
\end{tikzpicture}
\end{document}
如果你想切换到更现实的投影,你可以使用以下代码,它绘制金字塔,但你可以按照第节所述更改视角64 三点透视绘图库pgfmanual v3.1.5。
\documentclass[border=10pt, multi, tikz]{standalone}
\usetikzlibrary{perspective}
\tikzset{pics/pyramidoid/.style={code={
\tikzset{pyramidoid/.cd,#1}
\def\pv##1{\pgfkeysvalueof{/tikz/pyramidoid/##1}}
\draw [solid, opacity=.5, pic actions]
(tpp cs:x=0,y=0,z=0) coordinate (o)
(tpp cs:x=-\pv{scale}*\pv{width},y=0,z=0) coordinate (a)
(tpp cs:x=-\pv{scale}*\pv{width},y=\pv{scale}*\pv{depth},z=0) coordinate (b)
(tpp cs:x=0,y=\pv{scale}*\pv{depth},z=0) coordinate (c)
(tpp cs:x=-\pv{scale}*\pv{width}/2,y=\pv{scale}*\pv{depth}/2,z=\pv{scale}*\pv{height}) coordinate (d)
(o) edge[densely dashed] (c)
(c) edge[densely dashed] (b) edge[densely dashed] (d)
(o) -- (a) -- (b) -- (d) -- (a) (o) edge (d);
}},
pyramidoid/.cd,
width/.initial=10,
height/.initial=5,
depth/.initial=10,
scale/.initial=.2,
}
\begin{document}
\begin{tikzpicture}[3d view,line cap=round,line join=round,perspective]
\pic {pyramidoid={width=10, height=20, depth=10}};% Pyramide en PC (perspective cavalière)
\end{tikzpicture}
\end{document}
然后使用例如
\begin{tikzpicture}[3d view,line cap=round,line join=round,perspective={
q = {(0,5,0)}}]
\pic {pyramidoid={width=10, height=20, depth=10}};% Pyramide en PC (perspective cavalière)
\end{tikzpicture}
如果你把perspective
钥匙掉在地上,
\begin{tikzpicture}[3d view,line cap=round,line join=round]
\pic {pyramidoid={width=10, height=20, depth=10}};% Pyramide en PC (perspective cavalière)
\end{tikzpicture}
你得到