| 1 |
%-------------------------------------------------------------------- |
| 2 |
\newpage |
| 3 |
\section{Class \tkzClass{pfct}} |
| 4 |
\label{sec:class_pfct} |
| 5 |
|
| 6 |
The \tkzClass{pfct} class represents a parametric curve |
| 7 |
\[ |
| 8 |
t \longmapsto \bigl(x(t),y(t)\bigr), |
| 9 |
\] |
| 10 |
defined and evaluated in Lua. A \tkzClass{pfct} object encapsulates two |
| 11 |
expressions (or callable Lua functions) describing the $x$- and $y$-components |
| 12 |
of the curve, together with methods for evaluation, sampling, and geometric |
| 13 |
construction. |
| 14 |
|
| 15 |
By convention, parametric function objects are stored in a Lua table named |
| 16 |
\tkzVar{pfct}{PF}. Although this name is not mandatory, using \texttt{PF} is |
| 17 |
strongly recommended for consistency across examples and documentation. Each |
| 18 |
entry of \texttt{PF} associates a symbolic name (such as \texttt{lis}) with an |
| 19 |
object of class \tkzClass{pfct}. If a custom table name is used, it must be |
| 20 |
initialized manually. The \tkzFct{tkz-elements}{init\_elements()} function will |
| 21 |
reset the \texttt{PF} table if it has already been defined. |
| 22 |
|
| 23 |
\paragraph{Mathematical expressions.} |
| 24 |
All expressions defining a \tkzClass{pfct} object are evaluated using standard |
| 25 |
Lua rules. A \tkzClass{pfct} object can be evaluated at a parameter value, converted into |
| 26 |
points, sampled into a \tkzClass{path}, or exported to a data file suitable for |
| 27 |
TikZ \texttt{plot file} input. |
| 28 |
|
| 29 |
\paragraph{Important.} |
| 30 |
In function and parametric function definitions |
| 31 |
(\tkzClass{fct} and \tkzClass{pfct}), |
| 32 |
expressions must be written using standard mathematical notation. |
| 33 |
The Lua prefix \texttt{math.} must \emph{not} be used. |
| 34 |
|
| 35 |
In contrast, in all other methods and Lua code fragments of |
| 36 |
\tkzNamePack{tkz-elements}, |
| 37 |
standard Lua syntax applies, and the use of the prefix \texttt{math.} |
| 38 |
is required whenever a Lua mathematical function is called. For convenience, users may define local aliases in their Lua code, such as |
| 39 |
\code{local sin, cos, pi = math.sin, math.cos, math.pi}. |
| 40 |
|
| 41 |
\medskip |
| 42 |
Correct: |
| 43 |
\begin{verbatim} |
| 44 |
sin(x), exp(-x^2) |
| 45 |
\end{verbatim} |
| 46 |
|
| 47 |
Incorrect (in \tkzClass{fct} and \tkzClass{pfct}): |
| 48 |
\begin{verbatim} |
| 49 |
math.sin(x), math.exp(-x^2) |
| 50 |
\end{verbatim} |
| 51 |
|
| 52 |
\subsection{Methods of the class pfct} |
| 53 |
\vspace{1em} |
| 54 |
|
| 55 |
\bgroup |
| 56 |
\small |
| 57 |
\captionof{table}{pfct methods.}\label{pfct:methods} |
| 58 |
\begin{tabular}{ll} |
| 59 |
\toprule |
| 60 |
\texttt{Methods} & \texttt{Reference} \\ |
| 61 |
\midrule |
| 62 |
\texttt{Constructor} & \\ |
| 63 |
\midrule |
| 64 |
\tkzFct{pfct}{new(exprx,expry)} & [\ref{ssub:method_pfct_new}] \\ |
| 65 |
\tkzFct{pfct}{compile(exprx,expry)} & [\ref{ssub:method_pfct_compile}] \\ |
| 66 |
\midrule |
| 67 |
\texttt{Methods Returning a Real Number } & \\ |
| 68 |
\midrule |
| 69 |
\tkzMeth{pfct}{x(t)} & [\ref{ssub:method_pfct_x}] \\ |
| 70 |
\tkzMeth{pfct}{y(t)} & [\ref{ssub:method_pfct_y}] \\ |
| 71 |
\tkzMeth{pfct}{point(t)} & [\ref{ssub:method_pfct_point}] \\ |
| 72 |
\midrule |
| 73 |
\texttt{Methods Returning a Path} & \\ |
| 74 |
\midrule |
| 75 |
\tkzMeth{pfct}{path(tmin,tmax,n)} & [\ref{ssub:method_pfct_path}] \\ |
| 76 |
\bottomrule |
| 77 |
\end{tabular} |
| 78 |
\egroup |
| 79 |
|
| 80 |
%-------------------- details --------------------------------------- |
| 81 |
\subsubsection{Constructor \tkzFct{pfct}{new(exprx,expry)}} |
| 82 |
\label{ssub:method_pfct_new} |
| 83 |
|
| 84 |
\texttt{Description: }Creates a parametric function object from two expressions |
| 85 |
or callable Lua functions describing the components $x(t)$ and $y(t)$. When |
| 86 |
strings are provided, they represent Lua expressions in the variable |
| 87 |
\texttt{t}, evaluated using standard Lua rules (therefore requiring |
| 88 |
\texttt{math.} prefixes). |
| 89 |
|
| 90 |
\texttt{Arguments: }\par |
| 91 |
\begin{itemize} |
| 92 |
\item \code{exprx}: a string expression in \texttt{t}, or a callable Lua |
| 93 |
function representing $x(t)$; |
| 94 |
\item \code{expry}: a string expression in \texttt{t}, or a callable Lua |
| 95 |
function representing $y(t)$. |
| 96 |
\end{itemize} |
| 97 |
|
| 98 |
\texttt{Returns: } a \tkzClass{pfct} object. |
| 99 |
|
| 100 |
\subsubsection{Function \tkzFct{pfct}{compile(exprx,expry)}} |
| 101 |
\label{ssub:method_pfct_compile} |
| 102 |
|
| 103 |
\texttt{Description: }Compiles the two expressions defining $x(t)$ and $y(t)$ |
| 104 |
and returns the corresponding callable Lua functions (or wraps them into a |
| 105 |
\tkzClass{pfct} object, depending on the implementation). This is a low-level |
| 106 |
helper mainly intended for internal use. |
| 107 |
|
| 108 |
|
| 109 |
\subsubsection{Method \tkzMeth{pfct}{x(t)}} |
| 110 |
\label{ssub:method_pfct_x} |
| 111 |
|
| 112 |
\texttt{Description: }Evaluates the $x$-component of the parametric curve at |
| 113 |
parameter \code{t}. |
| 114 |
|
| 115 |
\medskip |
| 116 |
\texttt{Returns: } a number. |
| 117 |
|
| 118 |
\subsubsection{Method \tkzMeth{pfct}{y(t)}} |
| 119 |
\label{ssub:method_pfct_y} |
| 120 |
|
| 121 |
\texttt{Description: }Evaluates the $y$-component of the parametric curve at |
| 122 |
parameter \code{t}. |
| 123 |
|
| 124 |
\medskip |
| 125 |
\texttt{Returns: } a number. |
| 126 |
|
| 127 |
\subsubsection{Method \tkzMeth{pfct}{point(t)}} |
| 128 |
\label{ssub:method_pfct_point} |
| 129 |
|
| 130 |
|
| 131 |
\texttt{Description: }Constructs the point $(x(t),y(t))$ associated with the |
| 132 |
parametric curve. This method provides a direct bridge between numerical |
| 133 |
evaluation and geometric construction. |
| 134 |
|
| 135 |
\medskip |
| 136 |
\texttt{Returns: } a \tkzClass{point}. |
| 137 |
|
| 138 |
\medskip |
| 139 |
\texttt{Example: } |
| 140 |
\begin{tkzexample}[latex=.5\textwidth] |
| 141 |
\directlua{ |
| 142 |
init_elements() |
| 143 |
PF.lem = pfct("cos(t+pi/2)", "sin(2*t)") |
| 144 |
PA.courbe = PF.lem:path(0, 2*math.pi, 200) |
| 145 |
z.A = PF.lem:point(math.pi/8) |
| 146 |
} |
| 147 |
\begin{center} |
| 148 |
\begin{tikzpicture}[scale=2] |
| 149 |
\tkzGetNodes |
| 150 |
\tkzDrawCoordinates[smooth,cyan](PA.courbe) |
| 151 |
\tkzDrawPoint[red](A) |
| 152 |
\end{tikzpicture} |
| 153 |
\end{center} |
| 154 |
\end{tkzexample} |
| 155 |
|
| 156 |
\subsubsection{Method \tkzMeth{pfct}{path(tmin,tmax,n)}} |
| 157 |
\label{ssub:method_pfct_path} |
| 158 |
|
| 159 |
\texttt{Description: }Samples the parameter $t$ on the interval |
| 160 |
$[tmin,tmax]$ using \code{n} subdivisions and returns the corresponding |
| 161 |
\tkzClass{path}. Invalid values (NaN, infinities) may be skipped according to |
| 162 |
the internal policy. |
| 163 |
|
| 164 |
\texttt{Returns: } a \tkzClass{path}. |
| 165 |
|
| 166 |
\medskip |
| 167 |
\texttt{Example 1: } |
| 168 |
\begin{tkzexample}[latex=.4\textwidth] |
| 169 |
\directlua{ |
| 170 |
init_elements() |
| 171 |
PF.lis = pfct("sin(5*t)", "cos(3*t)") |
| 172 |
PA.curve = PF.lis:path(0, 2*math.pi, 400) |
| 173 |
} |
| 174 |
|
| 175 |
\begin{center} |
| 176 |
\begin{tikzpicture}[scale=2] |
| 177 |
\tkzDrawCoordinates[smooth,cyan](PA.curve) |
| 178 |
\end{tikzpicture} |
| 179 |
\end{center} |
| 180 |
\end{tkzexample} |
| 181 |
|
| 182 |
\medskip |
| 183 |
\texttt{Example 2: } |
| 184 |
\begin{tkzexample}[latex=.4\textwidth] |
| 185 |
\directlua{ |
| 186 |
init_elements() |
| 187 |
PF.ff = pfct("cos(t)+(t)*sin(t)", |
| 188 |
"sin(t)-(t)*cos(t)") |
| 189 |
PA.c_1 = PF.ff:path(0, math.pi, 1000) |
| 190 |
PA.c_2 = PF.ff:path(math.pi, 2 * math.pi, 1000) |
| 191 |
} |
| 192 |
\begin{center} |
| 193 |
\begin{tikzpicture}[scale=.75] |
| 194 |
\tkzInit[xmin=-5,xmax=2,ymin=-5,ymax=3] |
| 195 |
\tkzGrid |
| 196 |
\tkzAxeXY |
| 197 |
\tkzDrawCoordinates[smooth,thick,red](PA.c_1) |
| 198 |
\tkzDrawCoordinates[smooth,thick,cyan](PA.c_2) |
| 199 |
\end{tikzpicture} |
| 200 |
\end{center} |
| 201 |
\end{tkzexample} |
| 202 |
|
| 203 |
\medskip |
| 204 |
\texttt{Example 3: } |
| 205 |
\begin{tkzexample}[latex=.4\textwidth] |
| 206 |
\directlua{ |
| 207 |
init_elements() |
| 208 |
PF.ff = pfct("t * sin((1 / t))", "t * cos((1 / t))") |
| 209 |
PA.c_1 = PF.ff:path(math.pi/128, math.pi/16, 1000) |
| 210 |
PA.c_2 = PF.ff:path(math.pi/16, math.pi, 1000) |
| 211 |
PA.curve = PA.c_1 + PA.c_2 |
| 212 |
z.Ax = point(1, -1) |
| 213 |
z.Ay = point(1, 2.5) |
| 214 |
} |
| 215 |
|
| 216 |
\begin{center} |
| 217 |
\begin{tikzpicture}[scale=2] |
| 218 |
\tkzGetNodes |
| 219 |
\tkzInit[xmin=-1,xmax=1,ymin=-1,ymax=3] |
| 220 |
\tkzGrid |
| 221 |
\tkzDrawLine[thick,red](Ax,Ay) |
| 222 |
\tkzDrawX[label={$x(t) = t*sin((1/t)$}, |
| 223 |
below= -18pt,noticks=false] |
| 224 |
\tkzLabelX[text=blue,below = 3pt] |
| 225 |
\tkzDrawY[label={$y(t) = t*cos(1/t)$}, |
| 226 |
right= 18pt,noticks=false] |
| 227 |
\tkzDrawCoordinates[smooth,cyan](PA.curve) |
| 228 |
\end{tikzpicture} |
| 229 |
\end{center} |
| 230 |
\end{tkzexample} |
| 231 |
|
| 232 |
%-------------------------------------------------------------------- |
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
\endinput |
| 237 |
%-------------------------------------------------------------------- |