TikZ:将对角线阴影与相邻的水平和垂直三色阴影匹配

TikZ:将对角线阴影与相邻的水平和垂直三色阴影匹配

对于这个复杂的标题,我深表歉意,但我喜欢用标题来描述我的问题,并且想不出更简洁的版本。

关于矩形和其他形状的自定义阴影和淡入淡出,已经存在很多问题,但我无法在这些问题中找到我的问题的答案。所以,这就是答案。我有两个共用一个角的阴影矩形;该图用于解决物理问题:矩形代表地板和墙壁。它们具有相同的颜色渐变,但一个是垂直方向的,另一个是水平方向的。现在我想通过具有类似对角渐变的第三个矩形连接这两个矩形,但这没有奏效。

我知道为什么它不能按照我目前实现的方式工作(如果我没记错的话,它与 TikZ 获取旋转阴影的方式有关),但我无法实现一个工作版本。下面是以下 MWE 的渲染:

\documentclass[tikz,border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,shadings}
\begin{document}

\begin{tikzpicture}[x=2em,y=2em]
% Dimensions of the stuff
\pgfmathsetmacro\floorL{7}
\pgfmathsetmacro\boxL{\floorL/2}
\pgfmathsetmacro\boxH{\boxL/3.5}
\pgfmathsetmacro\wallH{2*\boxH}
\pgfmathsetmacro\floorD{\floorL/14}
\pgfmathsetmacro\wallD{\floorL/14}
% Define the stuff
% origin
\coordinate (O) at (0,0);
% floor
\coordinate (floorTL) at (O);
\coordinate (floorTR) at ($(floorTL)+(\floorL,0)$);
\coordinate (floorBL) at ($(floorTL)+(0,-\floorD)$);
\coordinate (floorBR) at ($(floorBL)+(\floorL,0)$);
% wall
\coordinate (wallBL) at (floorTR);
\coordinate (wallBR) at ($(wallBL)+(\wallD,0)$);
\coordinate (wallTL) at ($(wallBL)+(0,\wallH)$);
\coordinate (wallTR) at ($(wallTL)+(\wallD,0)$);
% Draw the stuff
% floor
\fill[bottom color=white,top color=brown!60!black,middle color=brown!80] (floorBL) rectangle (floorTR);
% wall
\fill[left color=brown!60!black,right color=white,middle color=brown!80] (wallBL) rectangle (wallTR);
% connect wall and floor
\shade[left color=brown!60!black,right color=white,middle color=brown!80,shading angle=45] (floorBR) rectangle (wallBR);
\end{tikzpicture}

\end{document}

在此处输入图片描述

我显然希望颜色能够匹配,那么是否可以通过一些相当简单/优雅的方式实现呢?

答案1

不是你所要求的,但我建议

在此处输入图片描述

\documentclass[tikz,border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,shadings}
\begin{document}

\begin{tikzpicture}[x=2em,y=2em]
% Dimensions of the stuff
\pgfmathsetmacro\floorL{7}
\pgfmathsetmacro\boxL{\floorL/2}
\pgfmathsetmacro\boxH{\boxL/3.5}
\pgfmathsetmacro\wallH{2*\boxH}
\pgfmathsetmacro\floorD{\floorL/14}
\pgfmathsetmacro\wallD{\floorL/14}
% Define the stuff
% origin
\coordinate (O) at (0,0);
% floor
\coordinate (floorTL) at (O);
\coordinate (floorTR) at ($(floorTL)+(\floorL,0)$);
\coordinate (floorBL) at ($(floorTL)+(0,-\floorD)$);
\coordinate (floorBR) at ($(floorBL)+(\floorL,0)$);
% wall
\coordinate (wallBL) at (floorTR);
\coordinate (wallBR) at ($(wallBL)+(\wallD,0)$);
\coordinate (wallTL) at ($(wallBL)+(0,\wallH)$);
\coordinate (wallTR) at ($(wallTL)+(\wallD,0)$);
% Draw the stuff
% floor
\shade [bottom color=white,top color=brown!60!black,middle color=brown!80] (floorBL) -- (wallBR |- floorBL) coordinate (c) -- (floorTR) -| cycle; 
% wall 
\shade [left color=brown!60!black,right color=white,middle color=brown!80] (wallBL) -- (c) -- (wallTR) -| cycle;
\end{tikzpicture}

\end{document}

相关内容