我目前正在将放大镜作为一个对象进行操作,但没有使用间谍库。由于我必须在一定程度上使用它,因此它被写为 \newcommand。我的问题是手柄的阴影。我使用 \shade,但只要我转到 90、180 或 270 以外的角度,阴影就会看起来很奇怪。画布变换产生了预期的效果,但由于我在范围内使用此命令进行缩放和移动,因此画布变换将放大镜放置在错误的坐标上。有没有办法像第一个放大镜一样为不同角度实现手柄的阴影,并在缩放或移动的范围内调用此命令时获得正确的坐标?
我希望问题清楚,我提前为坐标的奇怪构造道歉,我还没有清理代码。一个最小的例子如下
非常感谢
带有一些解释的最小示例:
第一个参数是放大镜中心的 x 坐标,第二个参数是 y 坐标。第三个参数是半径,第四个参数是手柄的角度。
\documentclass{article}
\usepackage{tikz} %Tikz ist kein Zeichenprogramm
\usepackage{tikz-3dplot} %3D Plots
\usetikzlibrary{arrows,intersections, decorations,circuits.ee.IEC, calc, decorations.markings,pgfplots.groupplots,3d,shadows,spy,fadings,fit}
\usepackage{pgfplots} %Für Plots
%\usepgfplotslibrary{groupplots}
\usepgfplotslibrary{polar}
\pgfplotsset{%
cycle list={blue\\red\\green\\orange\\},
every axis plot post/.append style={mark=none, smooth},
compat=1.11
}
\newcommand{\lupe}[4]{\Slupe{#1}{#2}{#3}{#4}{5}{#3*.15}{.5}{.05}}
\newcommand{\Slupe}[8]{
\begin{scope}[rotate around={#4:(#1,#2)}]
%\begin{scope}[transform canvas={rotate around={#4:(#1,#2)}}]
\draw [name path=Glassrand] (#1,#2) circle (#3);
\shade[ball color=blue,opacity=#8] (#1,#2) circle (0.95*#3);
\draw[fill=gray,even odd rule] (#1,#2) circle (#3) circle (0.95*#3) ;
\draw (#1,#2) circle (0.95*#3);
\path[draw=none,name path=linkerstiel] (#1,#2)--++ (0:#3+#3)--++(0+90:#6)--(#1,#2);
\path[draw=none,name path=rechterstiel] (#1,#2)--++ (0:#3+#3)--++(0-90:#6)--(#1,#2);
\path[draw=none,name path=linkerstielcenter] (#1,#2)--++(90:#6) coordinate (StielBreite1);
\path[draw=none,name path=rechterstielcebter] (#1,#2)--++(-90:#6) coordinate (StielBreite2);
\path[draw=none] (#1,#2) --++ (0:3*#3) --++(90:#6) coordinate (StielEnde1);
\path[draw=none] (#1,#2) --++ (0:3*#3)--++(-90:#6) coordinate (StielEnde2);
\path[draw=none,name path=StielAusrichtungEins] (StielEnde1) -- (StielBreite1);
\path[draw=none,name path=StielAusrichtungZwei] (StielEnde2) -- (StielBreite2);
\path [name intersections={of=Glassrand and StielAusrichtungEins}];
\coordinate (StielAnfang1) at (intersection-1);
\path [name intersections={of=Glassrand and StielAusrichtungZwei}];
\coordinate (StielAnfang2) at (intersection-1);
\coordinate (griff1) at ($(StielAnfang1) !1! (StielEnde1)$);
\coordinate (griff2) at ($(StielAnfang2) !1! (StielEnde2)$);
\coordinate (griff3) at ($(StielAnfang1) !.15! (StielEnde1)$);
\coordinate (griff4) at ($(StielAnfang2) !.15! (StielEnde2)$);
\path (griff3)--++(0,.1*#3) coordinate (griff5);
\path (griff4)--++(0,-.1*#3) coordinate (griff6);
\path (StielEnde1)--++(0,.1*#3) coordinate (griff7);
\path (StielEnde2)--++(0,-.1*#3) coordinate (griff8);
\coordinate (fixpunkt1) at ($(griff7)!.3!(griff8)$);
\coordinate (fixpunkt2) at ($(griff5)!.3!(griff6)$);
\coordinate (fixpunkt3) at ($(StielAnfang1)!.3!(StielAnfang2)$);
\coordinate (fixpunkt4) at ($(griff1)!.3!(griff2)$);
\path [draw=none] (griff1) --++(0,.1*#3) coordinate (test1);
\path [draw=none] (griff1) --++(.1*#3,0) coordinate (test2);
\path [draw=none] (griff2) --++(0,-.1*#3) coordinate (test3);
\path [draw=none] (griff2) --++(.1*#3,0) coordinate (test4);
\shade[top color=black, bottom color=white,shading angle=#4] (StielAnfang1) -- (fixpunkt3)--(fixpunkt4) -- (griff1);
\shade[top color=white, bottom color=black,shading angle=#4] (StielAnfang2) -- (fixpunkt3)--(fixpunkt4) -- (griff2);
\%end{scope}
\end{scope}
}
\begin{document}
\begin{tikzpicture}
\lupe{0}{0}{1}{0}
\lupe{0}{-2}{1}{-45}
\end{tikzpicture}
\end{document}
答案1
我尝试让手柄上的灯光与手柄的位置保持一致。您可以通过修改函数来修改结果
forHColor
。我简化了手柄的构造;它基于点
\H{+}
和的介绍\H{-}
。
\documentclass[11pt, border=1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc, math}
\begin{document}
\tikzmath{
function forHColor(\i, \b) {
if \b<91 then {
return 50*(cos((1-\i)^2*360)+1);
} else {
return 50*(cos(\i^2*360)+1);
};
};
}
\tikzset{
pics/magnifying/.code args={xcenter #1, ycenter #2, radius #3, hangle #4}{
\tikzmath{
coordinate \H{+}, H{-};
real \width, \da, \qw;
\da = 8; % controls handle's width
\H{+} = (#1, #2) + (#4+\da : #3);
\H{-} = (#1, #2) + (#4-\da : #3);
\width = veclen(\Hx{+}-\Hx{-}, \Hy{+}-\Hy{-}); % handle's width
\qw = .05; % controls the number of steps for handle's color
{%
\foreach \i [evaluate=\i as \cm using {forHColor(\i, #4)}]
in {0, \qw, ..., 1}{%
\draw[gray!70!black!\cm, line width={\width/10}]
($(\H{+})!\i!(\H{-})$) -- ++(#4 : 2.1*#3); % handle's length
}
};
{ \shade[ball color=blue, opacity=.07] (#1, #2) circle (.95*#3);
\draw[very thin, fill=gray, even odd rule]
(#1, #2) circle (#3) circle (.95*#3);
};
}
}
}
\begin{tikzpicture}
\draw pic {magnifying={xcenter -1, ycenter -2, radius 1.4, hangle 30}};
\draw pic {magnifying={xcenter 5, ycenter 0, radius 1.7, hangle 130}};
\end{tikzpicture}
\end{document}