答案1
我试图理解在网上找到的一些公式。
- 划分X和是坐标值等于某个值。
- 计算到该点的距离。
- 计算 1 + 因子 * 距离X和是价值。
我没有通过使用图像( )或仅仅是节点\includegraphics
中的纯文本获得任何有趣的结果。\pgftext
代码
\documentclass[tikz]{standalone}
\usepgfmodule{nonlineartransformations}
\pgfset{
barrel x factor/.initial=.3,
barrel y factor/.initial=.3,
barrel factor/.style={
/pgf/barrel x factor/.evaluated={#1},
/pgf/barrel y factor/.evaluated={#1}},
barrel width/.initial =5cm,
barrel height/.initial =5cm,
barrel size/.style={
/pgf/barrel width/.evaluated={#1},
/pgf/barrel height/.evaluated={#1}}}
\makeatletter
\newcommand*\pgfbarreldistortion{%
% xa, ya = original point
\pgf@xa=\pgf@x
\pgf@ya=\pgf@y
% divide lengths by something (make it smaller)
\pgfmathdivide@{\pgf@xa}{\pgfkeysvalueof{/pgf/barrel width}}%
\let\barrel@x\pgfmathresult
\pgfmathdivide@{\pgf@ya}{\pgfkeysvalueof{/pgf/barrel height}}%
\let\barrel@y\pgfmathresult
%
% calculate some radius
\pgfmathveclen@{\barrel@x}{\barrel@y}%
\let\barrel@radius\pgfmathresult
%
% 1 + factor * radius (but quicker)
\pgfmathmultiply@{\pgfkeysvalueof{/pgf/barrel x factor}}{\barrel@radius}%
\pgfmathadd@{\pgfmathresult}{1}%
\pgf@x=\pgfmathresult\pgf@xa
\pgfmathmultiply@{\pgfkeysvalueof{/pgf/barrel y factor}}{\barrel@radius}%
\pgfmathadd@{\pgfmathresult}{1}%
\pgf@y=\pgfmathresult\pgf@ya
}
\makeatother
\tikzset{
barrel/.code=\pgftransformnonlinear{\pgfbarreldistortion},
}
\begin{document}
\tikz{
\draw [help lines] (-5,-5) grid (5,5);
\draw [barrel, thick] (-5,-5) grid (5,5);
}
\tikz[barrel factor=-.1]{
\draw [help lines] (-5,-5) grid (5,5);
\draw [barrel, thick] (-5,-5) grid (5,5);
}
\end{document}