Debian Codegraph @

texmf-dist/doc/latex/tikz-ext/tikz-ext-manual-en-pgf-shapes-superellipse.tex

raw
1 % !TeX spellcheck = en_US
2 % !TeX root = tikz-ext-manual.tex
3 % Copyright 2022 by Qrrbrbirlbel
4 %
5 % This file may be distributed and/or modified
6 %
7 % 1. under the LaTeX Project Public License and/or
8 % 2. under the GNU Free Documentation License.
9 %
10
11 \section{Shape: Superellipse}
12 \begin{pgflibrary}{ext.shapes.superellipse}
13 Shape in the form of a ``superellipse''.
14 \inspiration{ShapeSuperEllipse-Q}{ShapeSuperEllipse-A}
15 \end{pgflibrary}
16
17 \begin{ext_shape}{superellipse}
18 This shape is defined by formula
19 \begin{equation*}
20 \biggl|\frac x{r_x}\biggr|^m + \biggl|\frac y{r_y}\biggr|^n = 1
21 \end{equation*}
22 and will be plotted by
23 \begin{align*}
24 x(t) &= |\cos t|^{\frac 2m} \cdot r_x \sgn(\cos t) \\
25 y(t) &= |\sin t|^{\frac 2n} \cdot r_y \sgn(\sin t) \\
26 \end{align*}
27 where $r_x$ is half the node's width and $r_y$ is half the node's height.
28
29 \begin{key}{/\pgfext/superellipse x exponent=\meta{x exponent}(initially 2.5)}\keycompat{pgf}
30 This sets $m$.
31 \end{key}
32 \begin{key}{/\pgfext/superellipse y exponent=\meta{y exponent}(initially 2.5)}\keycompat{pgf}
33 This sets $n$.
34 \end{key}
35 \begin{key}{/\pgfext/superellipse step=\meta{step}(initially 5)}
36 This specifies the step of the underlying plot handler.
37 The smaller \meta{step} is, the slower computation will be.
38
39 Sensible values for \meta{step} are integer dividers of 90, i.\,e.
40 2, 3, 5, 6, 9, 10, 15, 18, 30 and 45.
41 \end{key}
42 \begin{key}{/\pgfext/superellipse exponent=\meta{exponent}}\keycompat{pgf}
43 Sets both |superellipse x exponent| and |superellipse y exponent| to \meta{exponent}.
44 \end{key}
45
46 \paragraph{Notes on Implementation}
47 For implementing this shape, additional mathematical functions were declared.
48 \begin{math-function}{ext\textunderscore superellipsex(\mvar{t}, \mvar{2/m}, \mvar{$r_x$})}
49 \mathcommand[extsuperellipsex(\mvar{t}, \mvar{2/m}, \mvar{$r_x$})]
50 Returns the $x$ value on a point of the superellipse with its center on the origin following
51 \begin{equation*}
52 x = r_x\cos^{2/m} t
53 \end{equation*}
54 for values of $0 \leq t \leq 90$.
55 \end{math-function}
56 \begin{math-function}{ext\textunderscore superellipsey(\mvar{t}, \mvar{2/n}, \mvar{$r_y$})}
57 \mathcommand[extsuperellipsey(\mvar{t}, \mvar{2/m}, \mvar{$r_x$})]
58 Returns the $y$ value on a point of the superellipse with its center on the origin following
59 \begin{equation*}
60 y = r_y\cos^{2/n} t
61 \end{equation*}
62 for values of $0 \leq t \leq 90$.
63 \end{math-function}
64
65 Both \pgfname math functions can be used at once with the following macro.
66 \begin{command}{\pgfextmathsuperellipseXY\marg{t}\marg{2/m}\marg{2/n}\marg{a}\marg{b}}
67 Returns the $x$ value (in |\pgfmathresultX|) and the $y$ value (in |\pgfmathresultY|) of the superellipse with its center on the origin following
68 \begin{align*}
69 x & = a\cos^{2/m} t \\
70 y & = b\cos^{2/n} t
71 \end{align*}
72 for values of $0 \leq t \leq 90$.
73
74 Note: all arguments must be a valid number since they will not be parsed by \pgfname math.
75 \end{command}
76
77 \begin{codeexample}[preamble=\usetikzlibrary{ext.shapes.superellipse}]
78 \begin{tikzpicture}[ext/superellipse step=1]\Huge
79 \node[name=s,shape=ext_superellipse,shape example] {Superellipse\vrule width 1pt height 2cm};
80 \foreach \anchor/\placement in
81 {north west/above left, north/above, north east/above right,
82 west/left, center/above, east/right,
83 mid west/right, mid/above, mid east/left,
84 base west/left, base/below, base east/right,
85 south west/below left, south/below, south east/below right,
86 text/left, 10/right, 130/above}
87 \draw[shift=(s.\anchor)] plot[mark=x] coordinates{(0,0)}
88 node[\placement] {\scriptsize\texttt{(s.\anchor)}};
89 \end{tikzpicture}
90 \end{codeexample}
91 %
92 \begin{codeexample}[width=8cm,preamble=\usetikzlibrary{ext.shapes.superellipse}]
93 \begin{tikzpicture}[minimum width=1cm, minimum height=3cm]
94 \foreach \xe/\ye[count=\i] in {.5/.5, 1/1, 2/2, 3/3, .5/5}
95 \node[draw, ext_superellipse, ext/superellipse x exponent=\xe, ext/superellipse y exponent=\ye] at (1.5*\i,0) {};
96 \end{tikzpicture}
97 \end{codeexample}
98 \end{ext_shape}
99 \endinput