# Nonlinear transformation of tikzpicture according to a function

How does one can transform tikzpicture according some shape, which is given by an equation?

\documentclass[tikz]{standalone}

\usepgfmodule{nonlineartransformations}

\makeatletter
\def\mytransformation{%
% Code for transformation x = const lines to parabolic type
}
\makeatother

\begin{document}
\begin{tikzpicture}
\begin{scope}%Inside the scope transformation is active
\pgftransformnonlinear{\mytransformation}
\draw (0,0) grid [step=1] (10,10);
\draw[thick, domain=0:8.95, smooth,variable=\x,blue] plot ({\x},{8 - 0.1*\x*\x});
\end{scope}
% Here back to normal

\end{tikzpicture}

\end{document}


The main purpose, is to deform picture like shown in video (1:01) (right picture)

• what is the transformation equation ? – percusse Apr 15 '18 at 20:26
• This picture shows two transformations, the one of the path (left) and the one of the grid (right). Which one are you after? – user121799 Apr 15 '18 at 20:28
• @marmot The picture show the curved line in flat spacetime (Newtionian point of view) and straight line in curved spacetime (Einstein point of view). I want to look at this by using tikz nonlinear transformation from flat grid to curved grid. – sergiokapone Apr 15 '18 at 20:32
• Yes but what is the curvature relation? – percusse Apr 15 '18 at 20:33
• @ percusse I think it is parabola y = c x^2, straight lines x = const becomes to curved lines. Diff eq dx/dy = Csqrt(x) – sergiokapone Apr 15 '18 at 20:36

## 1 Answer

Here is a proposal. I stress that this proposal is just a cartoon. One could (or should) solve the Einstein equation for this, but this is not a physics forum. (Plus the video you are sharing is also not 100% accurate, so a cartoon may be OK for now.) \documentclass[tikz,border=3mm]{standalone}

\usepgfmodule{nonlineartransformations}

\makeatletter
\def\mytransformation{%
\pgfmathsetmacro{\myX}{\pgf@x}
\pgfmathsetmacro{\myY}{0.001*\pgf@x*\pgf@x+\pgf@y}
\setlength{\pgf@x}{\myX pt}
\setlength{\pgf@y}{\myY pt}
}
\makeatother

\begin{document}
\begin{tikzpicture}
\begin{scope}%Inside the scope transformation is active
\pgftransformnonlinear{\mytransformation}
\draw (0,0) grid [step=1] (10,10);
\draw[thick, domain=0:8.95, smooth,variable=\x,blue] plot ({\x},{8 - 0.03*\x*\x});
\end{scope}
% Here back to normal

\end{tikzpicture}

\end{document}

• Thank You. Solution of Einstein equations is known for this case, is ds^2 = (1 + 2gy)dy^2 - dx^2. But I do not interested in physics in this post, I interested in realisation with tikz. Now I see, how it can be done. – sergiokapone Apr 15 '18 at 20:44
• @sergiokapone Thanks for reminding me of the solution of the Einstein equation. ;-) I adjusted my answer accordingly. – user121799 Apr 15 '18 at 20:46