summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/tikz-ext/tikz-ext-manual-en-pgf-shapes-superellipse.tex
blob: 580ef0d93ff6a22ab2306e52a8896448e2ace9c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
% !TeX spellcheck = en_US
% !TeX root = tikz-ext-manual.tex
% Copyright 2022 by Qrrbrbirlbel
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Free Documentation License.
%

\section{Shape: Superellipse}
\begin{pgflibrary}{ext.shapes.superellipse}
  Shape in the form of a ``superellipse''.
  \inspiration{ShapeSuperEllipse-Q}{ShapeSuperEllipse-A}
\end{pgflibrary}

\begin{shape}{superellipse}
This shape is defined by formula
\begin{equation*}
  \biggl|\frac x{r_x}\biggr|^m + \biggl|\frac y{r_y}\biggr|^n = 1
\end{equation*}
and will be plotted by
\begin{align*}
  x(t) &= |\cos t|^{\frac 2m} \cdot r_x \sgn(\cos t) \\
  y(t) &= |\sin t|^{\frac 2n} \cdot r_y \sgn(\sin t) \\
\end{align*}
where $r_x$ is half the node's width and $r_y$ is half the node's height.

\begin{key}{/pgf/superellipse x exponent=\meta{x exponent}(initially 2.5)}
This sets $m$.
\end{key}
\begin{key}{/pgf/superellipse y exponent=\meta{y exponent}(initially 2.5)}
This sets $n$.
\end{key}
\begin{key}{/pgf/superellipse step=\meta{step}(initially 5)}
This specifies the step of the underlying plot handler.
The smaller \meta{step} is, the slower computation will be.

Sensible values for \meta{step} are integer dividers of 90, i.\,e.
2, 3, 5, 6, 9, 10, 15, 18, 30 and 45.
\end{key}
\begin{key}{/pgf/superellipse exponent=\meta{exponent}}
  Sets both |superellipse x exponent| and |superellipse y exponent| to \meta{exponent}.
\end{key}

\paragraph{Notes on Implementation}
For implementing this shape, additional mathematical functions were declared.
\begin{math-function}{superellipsex(\mvar{t}, \mvar{2/m}, \mvar{$r_x$})}
\mathcommand
Returns the $x$ value on a point of the superellipse with its center on the origin following
\begin{equation*}
   x = r_x\cos^{2/m} t
\end{equation*}
for values of $0 \leq t \leq 90$.
\end{math-function}
\begin{math-function}{superellipsey(\mvar{t}, \mvar{2/n}, \mvar{$r_y$})}
\mathcommand
Returns the $y$ value on a point of the superellipse with its center on the origin following
\begin{equation*}
   y = r_y\cos^{2/n} t
\end{equation*}
for values of $0 \leq t \leq 90$.
\end{math-function}

Both \pgfname math functions can be used at once with the following macro.
\begin{command}{\pgfmathsuperellipseXY\marg{t}\marg{2/m}\marg{2/n}\marg{a}\marg{b}}
Returns the $x$ value (in |\pgfmathresultX|) and the $y$ value (in |\pgfmathresultY|) of the superellipse with its center on the origin following
\begin{align*}
   x & = a\cos^{2/m} t \\
   y & = b\cos^{2/n} t
\end{align*}
for values of $0 \leq t \leq 90$.

Note: all arguments must be a valid number since they will not be parsed by \pgfname math.
\end{command}

And additional internal macro was defined following the original naming scheme.
\def\temp{\begin{command}}%
\expandafter\temp\expandafter{\csname pgfutil@prefix@macrotomacro\endcsname\marg{macro 1}\marg{macro 2}}
Adds the once-expansion of \meta{macro 2} in front of \meta{macro 1}.
\end{command}

\begin{codeexample}[preamble=\usetikzlibrary{ext.shapes.superellipse}]
\begin{tikzpicture}[superellipse step=1]\Huge
\node[name=s,shape=superellipse,shape example] {Superellipse\vrule width 1pt height 2cm};
\foreach \anchor/\placement in
  {north west/above left, north/above, north east/above right,
   west/left, center/above, east/right,
   mid west/right, mid/above, mid east/left,
   base west/left, base/below, base east/right,
   south west/below left, south/below, south east/below right,
   text/left, 10/right, 130/above}
   \draw[shift=(s.\anchor)] plot[mark=x] coordinates{(0,0)}
     node[\placement] {\scriptsize\texttt{(s.\anchor)}};
\end{tikzpicture}
\end{codeexample}
%
\begin{codeexample}[width=8cm,preamble=\usetikzlibrary{ext.shapes.superellipse}]
\begin{tikzpicture}[minimum width=1cm, minimum height=3cm]
\foreach \xe/\ye[count=\i] in {.5/.5, 1/1, 2/2, 3/3, .5/5}
  \node[draw, superellipse, superellipse x exponent=\xe, superellipse y exponent=\ye] at (1.5*\i,0) {};
\end{tikzpicture}
\end{codeexample}
\end{shape}
\endinput