\section{The pt3d Class}

\subsection{Representation of Points and Vectors}

The usual space is $\mathbf R^3$, so points and vectors are triplets of real numbers, we will call them: 3D points. The class \emph{pt3d} (which is automatically loaded) allows you to manage 3D points, possible operations, and a number of methods and constants.

\begin{itemize}
    \item  Four triplets have specific names (global variables), namely:
    \begin{itemize}
        \item \varglob{pt3d.Origin}, which represents the triplet $(0,0,0)$.
        \item \varglob{pt3d.vecI}, which represents the triplet $(1,0,0)$.
        \item \varglob{pt3d.vecJ}, which represents the triplet $(0,1,0)$.
        \item \varglob{pt3d.vecK}, which represents the triplet $(0,0,1)$.
    \end{itemize}
    \item  To create a 3D point, there are three methods:
    \begin{itemize}
        \item Cartesian definition: the function \cmd{pt3d.M(x, y, z)} returns the triplet $(x,y,z)$. This triplet can also be obtained by doing: \code{x*vecI+y*vecJ+z*vecK}.
        \item Cylindrical definition: the function \cmd{pt3d.Mc(r, theta, z)} (angle expressed in radians) returns the triplet $(r\cos(\theta),r\sin(\theta),z)$.
        \item Spherical definition: the function \cmd{pt3d.Ms(r, theta, varphi)} returns the triplet $(r\cos(\theta)\sin(\varphi), r\sin(\theta)\sin(\varphi),r\cos(\varphi))$ (angles expressed in radians).
    \end{itemize}

    Accessing the components of a 3D point: if a variable $A$ denotes a 3D point, then its three components are $A.x$, $A.y$, and $A.z$.

    To test whether a variable $A$ designates a 3D point, we use the \cmd{pt3d.isPoint3d()} function, which returns a Boolean.

    Conversion: To convert a real or complex number into a 3D point, we use the \cmd{pt3d.toPoint3d()} function.
\end{itemize}


\subsection{Operations on 3D Points}

These operations are the usual operations with the usual symbols:
\begin{itemize}
    \item Addition (+), difference (-), and negative (-).
    \item The product by a scalar, if $k$ is a real number, \code{k*M(x,y,z)} returns \val{M(k*a,k*y,k*z)}.
    \item A 3D point can be divided by a scalar; for example, if $A$ and $B$ are two 3D points, then the midpoint is simply written $(A+B)/2$.
    \item The equality of two 3D points can be tested with the symbol =.
\end{itemize}

\subsection{Methods of the class \emph{pt3d}}

These are:
\begin{itemize}
    \item \cmd{pt3d.abs(u)}: Returns the Euclidean norm of the 3D point \argu{u}.

    \item \cmd{pt3d.abs2(u)}: Returns the squared Euclidean norm of the 3D point \argu{u}.

    \item \cmd{pt3d.N1(u)}: Returns the $1$-norm of the 3D point \argu{u}. If $u=M(x,y,z)$, then \code{pt3d.N1(u)} returns \val{$|x|+|y|+|z|$}.

    \item \cmd{pt3d.dot(u, v)}: Returns the dot product between the vectors (3d points) \argu{u} and \argu{v}.

    \item \cmd{pt3d.det(u, v, w)}: Returns the determinant between the vectors (3D points) \argu{u}, \argu{v}, and \argu{w}.

    \item \cmd{pt3d.prod(u, v)}: Returns the cross product between the vectors (3D points) \argu{u} and \argu{v}.

    \item \cmd{pt3d.angle3d(u, v \fac{, epsilon})}: Returns the angular difference (in radians) between the vectors (3D points) \argu{u} and \argu{v}, assumed to be non-zero. The (optional) argument \argu{epsilon} is $0$ by default; it indicates how close a given equality test is to a floating point.

    \item \cmd{pt3d.normalize(u)}: Returns the normalized vector (3D point) \argu{u} (returns \nil if $u$ is zero).

    \item \cmd{pt3d.round(u, nbDeci)}: Returns a 3D point whose components are those of the 3D point \argu{u} rounded to \argu{nbDeci} decimal places.

    \item \cmd{pt3d.isobar3d(L)}: Returns the isobarycenter of the 3D points in the list (table) \argu{L} (elements of \argu{u} that are not 3D points are ignored).

    \item \cmd{pt3d.insert3d(L, A \fac{, epsilon})}: This function inserts the 3D point \argu{A} into the list \argu{u}L, which must be a \textbf{variable} (and which will therefore be modified). Point \argu{A} is inserted \textbf{without duplicates} and the function returns its position (index) in list \argu{L} after insertion. The (optional) argument \argu{epsilon} is $0$ by default, indicating how closely the comparisons are made.
\end{itemize}


\subsection{Displaying a Variable in the Terminal}

The instruction \cmd{ld.whatis(variable \fac{, msg})} displays the type of the \argu{variable} and its contents in the terminal during compilation. Recognized types include the predefined types plus: \emph{complex number}, \emph{list of (complex) numbers}, and \emph{list of lists of (complex) numbers},  \emph{3D point}, \emph{list of 3D points}, \emph{list of lists of 3D points}. The argument \argu{msg} is an optional string (empty by default) which is displayed with the type to locate the variable in the terminal.

