summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/tkz/tkz-elements/doc/latex/TKZdoc-elements-classes.tex
blob: e993ce9abe806413f74ed4e90439b893e9af5d60 (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
\newpage

\section{Class and object} % (fold)
\label{sec:class_and_object}

\subsection{Class} % (fold)
\label{sub:class}

 Object-oriented programming (OOP) is defined as a programming model built on the concept of objects. An object can be defined as a data table that has unique attributes and methods (operations) that define its behavior.
 
 \vspace{1em}
A class is essentially a user-defined data type. It describes the contents of the objects that belong to it. A class is a  blueprint of an object, providing initial values for   attributes and implementations of methods\footnote{action which an object is able to perform.} common to all objects of a certain kind.
% subsection class (end)

\subsection{Object} % (fold)
\label{sub:object}
 An Object is an instance of a class. Each object contains attributes and methods. Attributes are information or object characteristics stored in the date table (called field). The methods define behavior.
 
  \vspace{1em}
 All objects in the package are typed. The object types currently defined and used are: \tkzNameObj{point}, \tkzNameObj{line}, \tkzNameObj{circle}, \tkzNameObj{triangle}, \tkzNameObj{ellipse}, \tkzNameObj{quadrilateral}, \tkzNameObj{square}, \tkzNameObj{rectangle}, \tkzNameObj{parallelogram} and \tkzNameObj{regular\_polygon}. 

They can be created directly using the method \Imeth{obj}{new} by giving points, with the exception of the \Iclass{class}{point} class which requires a pair of reals, and \Iclass{class}{regular\_polygon} which needs two points and an integer.

 Objects can also be obtained by applying methods to other objects. For example, |T.ABC : circum_circle ()| creates an object \tkzNameObj{circle}. Some object attributes are also objects, such as |T.ABC.bc| which creates the object \tkzNameObj{line}, a straight line passing through the last two points defining the triangle.

 \vspace{1em}

 \subsubsection{Attributes} % (fold)
 \label{ssub:attributes}
 Attributes are accessed using the classic method, so |T.pc| gives the third point  of the triangle and |C.OH.center| gives the center of the circle, but I've added a |get_points| function that returns the points of an object. This applies to straight lines (pa and pc), triangles (pa, pb and pc) and circles (center and through).

  \vspace{1em}
  Example: |z.O,z.T = get_points (C)| recovers the center and a point of the circle.
 % subsubsection attributes (end)

\subsubsection{Methods} % (fold)
\label{ssub:methods}

A method is an operation (function or procedure) associated (linked) with an object.

Example:   The point object is used to vertically determine a new point object located at a certain distance from it (here 2). Then it is possible to rotate objects around it.

\begin{verbatim}
   \begin{tkzelements}
      z.A = point (1,0)
      z.B = z.A : north (2)             
      z.C = z.A : rotation (math.pi/3,z.B)
      tex.print(tostring(z.C))
   \end{tkzelements}
\end{verbatim}


\begin{tkzelements}
   z.A = point (1,0)
   z.B = z.A : north (2)
   z.C = z.A : rotation (math.pi/3,z.B)
   tex.print(tostring("The coordinates of $C$ are: " .. z.C.re .." and "..z.C.im))
\end{tkzelements}


% subsubsection methods (end)
% subsection object (end)
% section class_and_object (end)
\endinput