假设 OB 线是一条河流,AC 线是一条横跨河流的桥梁。我希望颜色从顶部 C 和 A 逐渐向“河流”OB 褪色。我相信我成功地为绿色三角形做到了这一点,但我无法为红色三角形做到这一点。
我希望颜色沿 A 到 N 的方向变化。无论我在下一条指令中的“褪色角度”如何:
\shade[shading=axis, left color=red,fading angle=-45,
opacity=0.8](AA)--(O)--(BB)--cycle;
它创建了一条从 N 到 OA 线的线。我使用“draw”、“shade”、“shadedraw”以及从 -180 到 180 的多种角度组合看到了这条从 N 向下的垂直线。垂直条纹始终存在。
就好像颜色沿着 BO 线变化而不是沿着 AN 线变化。如何才能实现从顶部 A 到河流 OB 的平滑渐变着色?
这是我的完整代码:它可以很好地与“lualatex”一起编译,但不能与“pdflatex”一起编译(我不知道为什么)。
\documentclass[12pt]{article}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usepackage{amssymb,amsmath}
\usepackage{amsfonts}
\begin{document}
\begin{tikzpicture}
\coordinate (A) at (2,0);
\coordinate (B) at (0,3);
\coordinate (O) at (0,0);
\tdplotsetmaincoords{70}{5}
\begin{scope}[tdplot_main_coords, scale=3.4]
% steep but good
%\def \x{ .526}
%\def \y{ 0.5}
%\def \z{0.69}
%\def \r{0.756}
%\coordinate (SOL) at (0.40480,0.5,0.76555);
%\coordinate (SOL) at (.6881909602355868,0.5,.5257311121191336);
\def \x{0.6881909602355868}
\def \y{0.5}
\def \z{0.5257311121191336}
\pgfmathsetmacro\r{sqrt(\x^2 + \y^2)}
% a bit flat but good.
%\def \x{ .7442506296788073}
%\def \y{ 0.574961742591969}
%\def \z{0.34}
%\def \r{0.94}
\coordinate (A) at (\x,\y,\z);
\coordinate (W) at (\x,-\y,\z);
\def \pi{180}
\def \beta{0.4*\pi}
\def \alpha{37.60599135740172}
\pgfmathsetmacro\bx{\r*cos(\beta+\alpha)}
\pgfmathsetmacro\by{\r*sin(\beta+\alpha)}
\coordinate (B) at (\bx,\by, \z);
\def \beta{0.8*\pi}
\pgfmathsetmacro\cx{\r*cos(\beta+\alpha)}
\pgfmathsetmacro\cy{\r*sin(\beta+\alpha)}
\coordinate (C) at (\cx,\cy, \z);
\def \beta{1.2*\pi}
\pgfmathsetmacro\dx{\r*cos(\beta+\alpha)}
\pgfmathsetmacro\dy{\r*sin(\beta+\alpha)}
\coordinate (D) at (\dx,\dy, \z);
\def \beta{1.6*\pi}
\pgfmathsetmacro\ex{\r*cos(\beta+\alpha)}
\pgfmathsetmacro\ey{\r*sin(\beta+\alpha)}
\coordinate (E) at (\ex,\ey, \z);
\pgfmathsetmacro\mx{0.5*\bx + 0.5*\ex}
\pgfmathsetmacro\my{0.5*\by + 0.5*\ey}
\pgfmathsetmacro\nx{0.5*\x}
\pgfmathsetmacro\ny{0.5*\y}
\pgfmathsetmacro\nz{0.5*\z}
\coordinate (N) at (\nx,\ny, \nz);
\pgfmathsetmacro\bpx{0.4*\x}
\pgfmathsetmacro\bpy{0.4*\y}
\pgfmathsetmacro\bpz{0.4*\z}
\coordinate (Bp) at (\bpx,\bpy, \bpz);
\coordinate (O) at (0,0,0);
% rename due to rotation
\coordinate (AA) at (E);
\coordinate (BB) at (A);
\coordinate (CC) at (B);
\coordinate (DD) at (C);
\coordinate (EE) at (D);
\coordinate (M) at (\mx,\my, \z);
\draw[] (M)--(N);
\node[] at (M) {\; \; \tiny $M$};
\node[yshift=1mm] at (N) {\tiny \; $N$};
\node[] at (A) {\; \; \tiny $B$};
\node[yshift=1mm] at (B) { \; \tiny $C$};
%\draw[color=red, fill=none](A)--(B)--(CC);
\fill[left color=white, right color=red, opacity=0.2](M)--(N)--(CC)--cycle;
\shade[shading=axis, left color=red,fading angle=-45,
opacity=0.8](AA)--(O)--(BB)--cycle;
\shade[top color=red, left color=white, opacity=0.6](AA)--(O)--(BB)--cycle;
%\draw[color=red](AA)--(BB);
%\draw[color=red](BB)--(CC);
\shade[shading=axis,bottom color=green!60,top color=black,shading angle=60,
opacity=0.6] (O)--(BB)--(CC)--cycle;
% this should be E
\node[] at (E) {\; \; \tiny $A$};
\node[anchor=north] at (O) {\tiny $O$};
\draw[line width=0.5] (CC)--(AA);
\draw[line width=0.5] (N)--(AA);
\draw[line width=0.5] (CC)--(M)--(N)--cycle;
% lower cone
%\draw[line width=0.5, color=red] (O)--(AA);
\draw[line width=0.5, color=red, dotted] (O)--(BB);
% \draw[line width=0.5, color=red] (O)--(Bp);
% \draw[line width=0.5, color=red] (O)--(CC);
\coordinate (P1) at (0,-0.1, \z1);
\node[yshift=4mm, xshift=-3.5mm] at (N) {\tiny $\delta$};
\end{scope}
\end{tikzpicture}
\end{document}
更新:
使用“tikz”包中的“shadings”库。即将“shadings”添加到 \usetikzlibrary{... , shadings , ...} 以及以下行:
\shade[lower left=red!20,lower right=red, upper left=blue,upper right=blue!20,
opacity=0.9] (AA)--(O)--(BB)--cycle;
我得到下图:
哪个更好。现在,这里有两个问题:
渐变并不完全符合我的要求。从 A 到 N。
为什么是平铺?紫色面的平铺和绿色面的孔隙度很奇怪。这是分辨率问题吗?我有两个显示 PDF 文件的工具:“okular”和“evince”,这是 PDF 问题吗?在我的两个显示工具中,我都可以看到紫色三角形上的网格。
谢谢。