3

I know that it is possible to write a text along a path.

I want to know is it possible to draw a shape along a path?

I know that this is impossible in most cases. but I think we can draw such shape for simple shapes like rectangle, circle, cube, ...e.g. suppose we have a circle inside a rectangle (distortion sample). by curving the edges of rectangle I want circle deformed proportionately. something like this:

enter image description here

  • This is what nonlinear transformations are good for. – user194703 Apr 2 at 15:27
  • This is a Tikz library? – C.F.G Apr 2 at 15:29
  • A pgf module. There is also curvilinear that allows you to transform something along a path. – user194703 Apr 2 at 15:30
  • 2
    Your profile image, the cat has a mask!! you are very up to date. – C.F.G Apr 2 at 15:32
  • Yes, I had to put it on because so many humans do not seem to understand what social distancing means.... – user194703 Apr 2 at 16:02
2

Here is one way to achieve something of that sort.

\documentclass[tikz,border=3mm]{standalone}
\usepgfmodule{nonlineartransformations}
\usetikzlibrary{fpu} 
\newcommand{\PgfmathsetmacroFPU}[2]{\begingroup%
\pgfkeys{/pgf/fpu,/pgf/fpu/output format=fixed}%
\pgfmathsetmacro{#1}{#2}%
\pgfmathsmuggle#1\endgroup}
\tikzset{declare function={xtransformed(\x,\y)=\pgfkeysvalueof{/tikz/trafos/a}*
    sign(\x)*\y*\y;},
trafos/.cd,a/.initial=pi}
\makeatletter
\def\mytransformation{%
\PgfmathsetmacroFPU{\myy}{\pgf@y}%
\PgfmathsetmacroFPU{\myx}{\pgf@x+xtransformed(\pgf@x/1cm,\pgf@y/1cm)}%\typeout{(\the\pgf@x,\the\pgf@y)|->(\myx pt,\myy pt)}
\pgf@x=\myx pt%
\pgf@y=\myy pt%
}
\makeatother
\begin{document}
\begin{tikzpicture}
\draw (-2,-2) rectangle (2,2);
\draw (0,0) circle [radius=pi/2];
\end{tikzpicture}
\begin{tikzpicture}
\begin{scope}
\pgftransformnonlinear{\mytransformation}
\draw (-2,-2) rectangle (2,2);
\draw (0,0) circle [radius=pi/2];
\end{scope}
\end{tikzpicture}
\end{document}

enter image description here

There is also the curvilinear library, but I think if you want to use it you'd need to split the picture in two halfs.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.