%--------------------------------------------------------------------
\newpage
\section{Class \tkzClass{pfct}}
\label{sec:class_pfct}

The \tkzClass{pfct} class represents a parametric curve
\[
t \longmapsto \bigl(x(t),y(t)\bigr),
\]
defined and evaluated in Lua. A \tkzClass{pfct} object encapsulates two
expressions (or callable Lua functions) describing the $x$- and $y$-components
of the curve, together with methods for evaluation, sampling, and geometric
construction.

By convention, parametric function objects are stored in a Lua table named
\tkzVar{pfct}{PF}. Although this name is not mandatory, using \texttt{PF} is
strongly recommended for consistency across examples and documentation. Each
entry of \texttt{PF} associates a symbolic name (such as \texttt{lis}) with an
object of class \tkzClass{pfct}. If a custom table name is used, it must be
initialized manually. The \tkzFct{tkz-elements}{init\_elements()} function will
reset the \texttt{PF} table if it has already been defined.

\paragraph{Mathematical expressions.}
All expressions defining a \tkzClass{pfct} object are evaluated using standard
Lua rules. A \tkzClass{pfct} object can be evaluated at a parameter value, converted into
points, sampled into a \tkzClass{path}, or exported to a data file suitable for
TikZ \texttt{plot file} input.

\paragraph{Important.}
In function and parametric function definitions
(\tkzClass{fct} and \tkzClass{pfct}),
expressions must be written using standard mathematical notation.
The Lua prefix \texttt{math.} must \emph{not} be used.

In contrast, in all other methods and Lua code fragments of
\tkzNamePack{tkz-elements},
standard Lua syntax applies, and the use of the prefix \texttt{math.}
is required whenever a Lua mathematical function is called. For convenience, users may define local aliases in their Lua code, such as
\code{local sin, cos, pi = math.sin, math.cos, math.pi}.

\medskip
Correct:
\begin{verbatim}
sin(x), exp(-x^2)
\end{verbatim}

Incorrect (in \tkzClass{fct} and \tkzClass{pfct}):
\begin{verbatim}
math.sin(x), math.exp(-x^2)
\end{verbatim}

\subsection{Methods of the class pfct}
\vspace{1em}

\bgroup
  \small
  \captionof{table}{pfct methods.}\label{pfct:methods}
  \begin{tabular}{ll}
  \toprule
  \texttt{Methods} & \texttt{Reference} \\
  \midrule
  \texttt{Constructor} & \\
  \midrule
  \tkzFct{pfct}{new(exprx,expry)}       & [\ref{ssub:method_pfct_new}] \\
  \tkzFct{pfct}{compile(exprx,expry)}   & [\ref{ssub:method_pfct_compile}] \\
  \midrule
  \texttt{Methods Returning a Real Number } & \\
  \midrule
  \tkzMeth{pfct}{x(t)}                 & [\ref{ssub:method_pfct_x}] \\
  \tkzMeth{pfct}{y(t)}                 & [\ref{ssub:method_pfct_y}] \\
  \tkzMeth{pfct}{point(t)}             & [\ref{ssub:method_pfct_point}] \\
  \midrule
  \texttt{Methods Returning a Path} & \\
  \midrule
  \tkzMeth{pfct}{path(tmin,tmax,n)}    & [\ref{ssub:method_pfct_path}] \\
  \bottomrule
  \end{tabular}
\egroup

%-------------------- details ---------------------------------------
\subsubsection{Constructor \tkzFct{pfct}{new(exprx,expry)}}
\label{ssub:method_pfct_new}

\texttt{Description: }Creates a parametric function object from two expressions
or callable Lua functions describing the components $x(t)$ and $y(t)$. When
strings are provided, they represent Lua expressions in the variable
\texttt{t}, evaluated using standard Lua rules (therefore requiring
\texttt{math.} prefixes).

\texttt{Arguments: }\par
\begin{itemize}
\item \code{exprx}: a string expression in \texttt{t}, or a callable Lua
      function representing $x(t)$;
\item \code{expry}: a string expression in \texttt{t}, or a callable Lua
      function representing $y(t)$.
\end{itemize}

\texttt{Returns: } a \tkzClass{pfct} object.

\subsubsection{Function \tkzFct{pfct}{compile(exprx,expry)}}
\label{ssub:method_pfct_compile}

\texttt{Description: }Compiles the two expressions defining $x(t)$ and $y(t)$
and returns the corresponding callable Lua functions (or wraps them into a
\tkzClass{pfct} object, depending on the implementation). This is a low-level
helper mainly intended for internal use.


\subsubsection{Method \tkzMeth{pfct}{x(t)}}
\label{ssub:method_pfct_x}

\texttt{Description: }Evaluates the $x$-component of the parametric curve at
parameter \code{t}.

\medskip
\texttt{Returns: } a number.

\subsubsection{Method \tkzMeth{pfct}{y(t)}}
\label{ssub:method_pfct_y}

\texttt{Description: }Evaluates the $y$-component of the parametric curve at
parameter \code{t}.

\medskip
\texttt{Returns: } a number.

\subsubsection{Method \tkzMeth{pfct}{point(t)}}
\label{ssub:method_pfct_point}


\texttt{Description: }Constructs the point $(x(t),y(t))$ associated with the
parametric curve. This method provides a direct bridge between numerical
evaluation and geometric construction.

\medskip
\texttt{Returns: } a \tkzClass{point}.

\medskip
\texttt{Example: }
\begin{tkzexample}[latex=.5\textwidth]
\directlua{
 init_elements()
 PF.lem = pfct("cos(t+pi/2)", "sin(2*t)")
 PA.courbe = PF.lem:path(0, 2*math.pi, 200)
 z.A = PF.lem:point(math.pi/8)
 }
\begin{center}
 \begin{tikzpicture}[scale=2]
\tkzGetNodes
  \tkzDrawCoordinates[smooth,cyan](PA.courbe)
  \tkzDrawPoint[red](A)
\end{tikzpicture}
 \end{center}
\end{tkzexample}

\subsubsection{Method \tkzMeth{pfct}{path(tmin,tmax,n)}}
\label{ssub:method_pfct_path}

\texttt{Description: }Samples the parameter $t$ on the interval
$[tmin,tmax]$ using \code{n} subdivisions and returns the corresponding
\tkzClass{path}. Invalid values (NaN, infinities) may be skipped according to
the internal policy.

\texttt{Returns: } a \tkzClass{path}.

\medskip
\texttt{Example 1: }
\begin{tkzexample}[latex=.4\textwidth]
\directlua{
 init_elements()
 PF.lis = pfct("sin(5*t)", "cos(3*t)")
 PA.curve = PF.lis:path(0, 2*math.pi, 400)
 }

\begin{center}
 \begin{tikzpicture}[scale=2]
  \tkzDrawCoordinates[smooth,cyan](PA.curve)
\end{tikzpicture}
 \end{center}
\end{tkzexample}

\medskip
\texttt{Example 2: }
\begin{tkzexample}[latex=.4\textwidth]
\directlua{
 init_elements()
 PF.ff = pfct("cos(t)+(t)*sin(t)",
              "sin(t)-(t)*cos(t)")
 PA.c_1 = PF.ff:path(0, math.pi, 1000)
 PA.c_2 = PF.ff:path(math.pi, 2 * math.pi, 1000)
 }
\begin{center}
 \begin{tikzpicture}[scale=.75]
  \tkzInit[xmin=-5,xmax=2,ymin=-5,ymax=3]
  \tkzGrid
  \tkzAxeXY
  \tkzDrawCoordinates[smooth,thick,red](PA.c_1)
  \tkzDrawCoordinates[smooth,thick,cyan](PA.c_2)
 \end{tikzpicture}
 \end{center}
 \end{tkzexample}

 \medskip
 \texttt{Example 3: }
 \begin{tkzexample}[latex=.4\textwidth]
\directlua{
  init_elements()
  PF.ff = pfct("t * sin((1 / t))", "t * cos((1 / t))")
  PA.c_1 = PF.ff:path(math.pi/128, math.pi/16, 1000)
  PA.c_2 = PF.ff:path(math.pi/16, math.pi, 1000)
  PA.curve = PA.c_1 + PA.c_2
  z.Ax = point(1, -1)
  z.Ay = point(1, 2.5)
  }

\begin{center}
   \begin{tikzpicture}[scale=2]
 \tkzGetNodes
 \tkzInit[xmin=-1,xmax=1,ymin=-1,ymax=3]
 \tkzGrid
 \tkzDrawLine[thick,red](Ax,Ay)
 \tkzDrawX[label={$x(t) = t*sin((1/t)$},
     below= -18pt,noticks=false]
 \tkzLabelX[text=blue,below = 3pt]
 \tkzDrawY[label={$y(t) = t*cos(1/t)$},
     right= 18pt,noticks=false]
 \tkzDrawCoordinates[smooth,cyan](PA.curve)
 \end{tikzpicture}
  \end{center}
  \end{tkzexample}

%--------------------------------------------------------------------



\endinput
%--------------------------------------------------------------------