这个问题与我发布的问题有关这里。我一直在尝试对矩形棱柱进行着色,使棱柱的整个下层为红色,上半层为蓝色。我有以下代码
\begin{tikzpicture}[join = round, xscale = 10.5, yscale = 6]
\colorlet{bcolor}{red!60}
\colorlet{tcolor}{blue!100}
\colorlet{ttcolor}{blue!100}
\shadedraw[bottom color = bcolor, top color = tcolor]
(-1,-1) coordinate (A) rectangle (0,0);
\shadedraw[xscale = 0.5, yslant = 0.5, bottom color = bcolor, top color = tcolor, shading angle = 25]
(0,-1) rectangle (1,0)
(1,-1) coordinate (B)
(-1,0) coordinate (O);
\draw[yscale = 0.5, xslant = 0.5, fill = ttcolor] (-1,0) rectangle (0,1) (-1,1) coordinate (C);
\draw[dashed, opacity = 0.7] (O)--(A) (O)--(B) (O)--(C);
\end{tikzpicture}
得出以下结论
这非常接近我想要的效果,尽管在棱镜的右侧表面上可以清楚地看到,表面顶部有点红色。如前所述,我希望这个区域是蓝色的,并与立方体顶面的颜色相匹配。无论我做什么,我都无法弄清楚如何获得正确的阴影。
所以,我的第一个问题是如何使最右侧面上的阴影在面的上半部分变成蓝色,以便它与棱镜顶部的颜色相匹配,而底部保持红色?
其次,我希望垂直叠加一些箭头通过棱镜,从棱镜底面下方稍下方开始,箭头略高于棱镜顶面。我根本无法弄清楚。有办法吗?
感谢您的帮助。
编辑:
使用下面答案中的代码(正确设置序言后)
\tdplotsetmaincoords{70}{110}
\begin{tikzpicture}[tdplot_main_coords,line cap=round,line join=round,
fill opacity=0.8,scale=2]
\path foreach \X in {-1,1} {foreach \Y in {-1,1}
{foreach \Z in {-1,1} {(\X,\Y,\Z) coordinate (p\X\Y\Z)}}};
\draw[dashed] (p-11-1) -- (p-1-1-1) edge (p-1-11) -- (p1-1-1);
\begin{scope}[canvas is xz plane at y=1]
\pgflowlevelsynccm
\draw[bottom color = red, top color = blue] (-1,-1) rectangle (1,1);
\end{scope}
\begin{scope}[canvas is yz plane at x=1]
\pgflowlevelsynccm
\draw[bottom color = red, top color = blue] (-1,-1) rectangle (1,1);
\end{scope}
\begin{scope}[canvas is xy plane at z=1]
\draw[fill=blue] (-1,-1) rectangle (1,1);
\end{scope}
\end{tikzpicture}
产量
答案1
这是一个转换阴影的版本。关键是\pgflowlevelsynccm
,它被使用transform canvas
,但不幸的是,transform canvas
它添加了一些旨在重置其他转换的内容,这在实践中会导致问题。
\documentclass[tikz,border=3mm]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{70}{110}
\begin{tikzpicture}[tdplot_main_coords,line cap=round,line join=round,
fill opacity=0.8,scale=2]
\path foreach \X in {-1,1} {foreach \Y in {-1,1}
{foreach \Z in {-1,1} {(\X,\Y,\Z) coordinate (p\X\Y\Z)}}};
\draw[dashed] (p-11-1) -- (p-1-1-1) edge (p-1-11) -- (p1-1-1);
\begin{scope}[canvas is xz plane at y=1]
\pgflowlevelsynccm
\draw[bottom color = red, top color = blue] (-1,-1) rectangle (1,1);
\end{scope}
\begin{scope}[canvas is yz plane at x=1]
\pgflowlevelsynccm
\draw[bottom color = red, top color = blue] (-1,-1) rectangle (1,1);
\end{scope}
\begin{scope}[canvas is xy plane at z=1]
\draw[fill=blue] (-1,-1) rectangle (1,1);
\end{scope}
\end{tikzpicture}
\end{document}