I am trying to define a style that sets to path
such that a “curvy rectangle” (manifold representation) is drawn when I put \draw (0,0) to[manifold] (5,3)
.
I have manually made the shape by specifying in
and out
angles in an absolute and then relative coordinate system and drawing the four corners using to
. (First and second example in MWE.)
I can draw the rectangle using a to path
style, as defined in the preamble. I am struggling with two problems, where I think I can solve (1) but don't know how to do (2):
- How to automatically move the SE and NW corners towards the centre, or (equivalently) 10% towards the SW and NE corners, like in the first example. (b there is moved a bit towards c and a). I can probably do that with calc and some
($(\tikztostart -| \tikztotarget)!0.9!(\tikztostart |- \tikztotarget)$)
magic. - Apply the
out=x,in=y,relative
to the paths internally in themanifold/.style
'spath to
operation. I have no idea how to do this.
For 2., I tried things I found in tikzlibrarytopaths.code.tex
, where e.g. out
is defined as a TikZ option that sets \def\tikz@to@out{#1}\tikz@to@switch@on
. Putting this in various places (currently in \pgfextra
in to path
) doesn't work. Can anybody help with this?
MWE
\documentclass[tikz]{standalone}
\makeatletter
\tikzset{manifold/.style={
to path={
\pgfextra{
\def\tikz@to@out{20}\tikz@to@switch@on
}
(\tikztostart) -- (\tikztostart -| \tikztotarget)
-- (\tikztotarget)
-- (\tikztostart |- \tikztotarget)
-- cycle
(\tikztotarget)
\tikztonodes
}
}}
\makeatother
\begin{document}
\begin{tikzpicture}[every node/.style={opacity=0.5,color=cyan}]
\draw[line width=0.5pt,dotted,red] (-1,-3) grid (5,7);
% base manifold: absolute in/out angles
\draw[thick] (0,0) node{a}
to[out=-10,in=170] (4,0.5) node{b}
to[out=70,in=-130] (5,3) node{c}
to[out=170,in=-10] (1,2.5) node{d}
to[out=-130,in=70] cycle;
% base manifold: relative in/out angles: all the same
\begin{scope}[shift={(0,-3)},out=-20,in=160,relative]
\draw (0,0) to (4,0.5) to (5,3) to (1,2.5) to cycle;
\end{scope}
% base manifold: to path style
\begin{scope}[shift={(0,3)}]
\draw[red] (0,0) to[manifold] (5,3);
\end{scope}
\end{tikzpicture}
\end{document}