Corresponding author: Ángel SerranoAroca (
Academic editor:
Programming a computer is an activity that can be very beneficial to undergraduate students in terms of improving their mental capabilities, collaborative attitudes and levels of engagement in learning. Despite the initial difficulties that typically arise when learning to program, there are several wellknown strategies to overcome them, providing a very high benefitcost ratio to most of the students. Moreover, the use of a programming language usually raises the interest of students to learn any specific concept, which has caused that many teachers around the world employ a programming language as a learning environment to treat almost every possible topic. Particularly, mathematics can be taught and learnt while using a suitable programming language. The R programming language is endowed with a wide range of capabilities that allow its use to learn different kind of concepts while programming. Therefore, complex subjects such as mathematics could be learnt with the help of this powerful programming language. In addition, since the R language provides numerous graphical functions, it could be very useful to acquire simultaneously basic plane geometry and programming knowledge at the undergraduate level. This paper describes the LearnGeom R package, a novel pedagogical tool, which contains multiple functions to learn geometry in R at different levels of difficulty, from the most basic geometric objects to highcomplexity geometric constructions, while developing numerous programming skills.
In the field of informatics, programming is the activity that basically consists of translating from human language to the language understood by a computer
In addition to its inherent importance in the computational sciences, learning to program provides powerful strategies for thinking, designing and solving problems
The nature of programming provides certain advantages to the user that very few mental activities can offer. For example, it allows the programmer to explore thinking processes, improve logical reasoning and increase capacity to correct mistakes
There are multiple studies that have confirmed the benefits of programming on young students. For example, already in the early 1970s, it was concluded in a survey conducted by
At the same time, there is little disagreement about the declaration of programming as a complex activity
In view of all these difficulties, what strategies should be followed for the correct teaching of programming? While being aware that each student learns in a different way, there are some accepted strategies in order to reduce, at least to a certain extent, the difficulties that arise when programming. In the first place, the choice of the programming language is key. The basic operating rules and the rigid syntax are common to all programming languages, but not all of them are equally accessible, especially from the point of view of a totally inexperienced user. The wide variety of languages available today, the majority of which are free software, render this task much easier.
Once the language has been conveniently chosen, different strategies can be carried out. Some methodological examples of successful programming teaching approaches include: simplifying and dividing problems into simpler subproblems, defining and explaining a model based on the machinelanguage environment in which the student is working
Learning through the use of a programming language can result more interesting and exciting for a student, and explains somehow why it has been used to teach and study mathematics during the last decades, with overall successful results, as described by
Currently, there are already some languages and programs focused on mathematics learning and teaching at undergraduate level, being Scratch
Scratch possesses most of the common features that are associated to a programming language. However, its style is predominantly graphical, which differs to the vast majority of programming languages. This graphical orientation clearly reduces the initial difficulty of learning to program, but also avoids the development of some other programming skills usually acquired in the classical educational way.
The ScratchMaths project
In addition, researchers such as
On the other hand, GeoGebra is dynamic mathematics software, which brings together geometry, algebra, spreadsheets, graphing, statistics and calculus in one easytouse package. Several works confirm the advantages of using GeoGebra at undergraduate level.
Another programming language, which is currently very popular is
For example,
In addition, since the R language provides numerous graphical functions, it can be very useful to simultaneously acquire basic plane geometry and R programming knowledge at the undergraduate level.
Therefore, in this work we present a novel pedagogical tool to simultaneously learn plane geometry and programming based on R, which we have denominated LearnGeom. This tool is available for secondary school teachers, which may be interested in teaching plane geometry and R programming skills at the same time, and may desire to complement the use of other languages and software with this R package. It can be downloaded once the R programming language is installed in your computer (
The LearnGeom R package provides basic functions to treat plane geometry. Therefore, the user is expected to work on a coordinate plane in order to manipulate different geometric objects and constructions. Thus, the function
All of them can be plotted in the coordinate plane with function
The first method to define a segment in the plane, which is the most basic one, consists of the choice of two points of the plane, P and Q, and applying the shortest path (in euclidean distance) to connect them. There is another common method to define a segment in the plane: from a starting point, choosing an angle and a length for the segment. Both possibilities can be achieved with the
An arc is simply a part of a circumference, or even the circumference itself. The
Polygons are closed figures made of a finite number of points (there must be 3 points at least). The segments that join the points of a polygon are called the sides of the polygon, and each of the sides must intersect only at the two points that connects (autointersections are not allowed in a polygon). It is usual to represent a polygon by an ordered list of points, which indicates the way the points are connected. For example, if a polygon is represented by a list of points [P1, P2,P3], it means that the three segments of this polygon (a triangle) join P1 with P2, P2 with P3 and P3 with P1. The
It is quite simple to make these objects with basic graphical R functions. However, the goal was to create a homogeneous group of functions with a minimal number of parameters. Although the already existing functions in the R language are simple for a programmer, they may contain too many parameters for a novice user. Moreover, it is essential to define the functions with a little number of parameters in order to highlight the different existing methods to define the same geometric object.
Finally, the
As a summary, Table
A brief explanation of the parameters which are associated to each of these functions can be found in Table
Table
Fig.
Fig.
Moreover, if a more experienced user of the language aims to create a line by specifying its slope and intercept, even though there is no function in the package to perform this, it can be achieved by simply defining a twodimensional vector containing these basic parameters of the line and appending the class
Affine functions are geometric transformations that preserve collinearity and ratios of distances. LearnGeom contains functions to apply six different affine transformations: homothety, reflection, rotation, shear, similarity and translation. Each of these transformations is associated with a 2 x 2 matrix, depending on one or several specific parameters.
All of these functions apply to polygons. However, they also can be used with lines and segments in the case of rotation and translation. For this reason, the names for the functions related to these transformation miss the word
The use of the affine transformations functions included in the package can be seen in Fig.
A reflection needs the definition of a line to be used as the axis of reflection, which can be built by the
The most familiar parameter related to this transformation is the angle of rotation, which is defined as 30º this time. However, this angle does not fully characterise this transformation because it is also necessary the only point remaining fixed after the transformation (for this example, point (2,0) of the triangle) (Fig.
A similarity only needs the selection of one parameter,
Translation simply represents the movement of a polygon in the direction of vector
Shear and homothety are the remaining affine transformations available in the package. Even though they are less common and known than the other four, they offer many possibilities to the user.
On the other hand, the function
We can appreciate a combined use of the package fuctions and the R language capabilities by obtaining a notable point of a triangle: its circumcenter, that is, the intersection of its three perpendicular bisector lines.
For example, consider the triangle of points (0,0), (1,1) and (2,0). The
In order to find the bisectors of the sides, it is necessary to find an orthogonal vector to each of them. Prior to that, the vectors that connect the three points have to be computed (defined as the difference between the points). Now, one alternative to find the orthogonal of each of these vectors consists of changing the order of the coordinates and the sign of one of them, as it is shown in the code in Fig.
The auxiliary points previously obtained are then connected to the middle points of the sides of the triangle through a line (see Figure Fig.
As it can be observed in these blocks of code, several functions of the package reduce the difficulty of some of the steps, allowing the user to focus on the most advanced topics involved in the resolution of the problem, such as orthogonality and operations on points and vectors.
A tessellation, also known as a tiling, is a pattern that is made by repeating a basic geometric figure, or combination of figures, along a plane
The process starts with the creation of a regular hexagon in the plane (see Fig.
In order to obtain two hexagons that are contiguous to the initial one,
The final step requires the use of the
The
The function
>
>
>
>
>
>
Recursive programming is one of the most efficient strategies to find the solution of some problems. However, it is also a difficult task for novice programmers. For quite advanced students, recursive programming could be treated to build a wellknown mathematical structure: a fractal
As an illustration, this definition can be easily imagined with the help of one of the most famous fractals: the Sierpinski triangle
Start from an equilateral triangle.
Find the middle points of each side of this triangle.
Connect the three points obtained in step 2 to obtain a new triangle. This triangle is also equilateral and rotated 180º with respect to the initial position.
Remove the triangle built in step 2 from the initial triangle. Now you have three little triangles inside the initial one. This is the first iteration to build the Sierpinski triangle.
If the steps 14 are repeated in each of these three triangles, nine smaller triangles will be obtained, which are similar to the previous ones. This is already the second iteration of the construction and a constant repetition of the steps leads to any iteration of the triangle. The Sierpinski triangle is theoretically defined as the infinite repetition of the steps 14. However, from a practical point of view, we consider interesting only the building of the first iterations. This process can be implemented in R with a few lines of code due to the efficiency of recursive programming and some of the functions contained in the LearnGeom R package. For example, the code available in the following lines (in
>
>
>
>
>
>
>
The R code included just displayed is basically the same one that contains the function
Divide the segment into three equal segments.
Replace the middle segment by the two sides of an equilateral triangle whose side length is the same as for the segment being removed. Now, there are four segments of the same length.
Build an equilateral triangle by using the middle segment as its base. Remove this segment to leave four different segments in the picture.
The continuous application of these steps to each of the new segments that are created after each iteration produces every state of the fractal. The
A trochoid is a closed curve that can be obtained by the conjunction of three geometric figures: two circles, from which one of them is fixed and the other mobile, and a mobile point, which is connected to the mobile circle. There are three parameters to characterize each trochoid: the fixed circle radius, the mobile circle radius and the distance from the mobile point to the center of the mobile circle
The presence of these parameters can be used to define a trochoid as a set of parametrical equations, involving trigonometry functions. However, as it was first proposed by
This package also includes a function called
Currently, there are some powerful and useful free software products, such as GeoGebra and Scratch, to learn geometry at undergraduate level. However, all of them present some limitations when compared to common programming languages. Although the R programming language is mainly focused on statistical computing, it can also be employed as a pedagogical tool for simultaneously learning mathematical concepts and advanced programming skills. In this work, an R programming package named LearnGeom is presented as a novel pedagogical tool that provides a set of functions to facilitate the exploration of plane geometry while programming in R. Beginning with some easy functions and definitions, the combined use of the functions included in the package with the own capabilities of the language itself offers a novel teaching source for current secondary educators.
The authors declare that they have no conflict of interest.
The authors would like to acknowledge the Universidad Católica de Valencia San Vicente Mártir and the Ministry of Economy, Industry and Competitiveness for the financial support of this work through the 2018231001UCV and MAT201569315C31R grants respectively.
Several examples of use of some of the basic functions included in the LearnGeom R package with their required lines of code to produce them.
Three polygons created with the
Regular polygons with 9 or less sides created with
Example of use of the
Example of use of the
Examples of use of the
Examples of use of the
Examples of use of the specific functions for lines and segments creation. The coincidence in the outputs is due to the choice of equivalent parameters, which are visible in their corresponding figures.
Example of use of
Example of use of
Example of use of
Example of use of
Examples of use of the functions included in the package that represent affine transformations in the plane. In all the pictures, the blue triangle, placed at the points A(0,0), B(2,0) and C(1,1), is the one passed to each of the functions, being the orange triangle the output resulting for each of the transformations.
A reflection.
A rotation.
A similarity.
A translation.
A shear transformation.
A homothety.
Partial results during the process of finding the circumcenter of the triangle of points (1,0), (0,1) and (1,0).
Triangle creation and obtention of the middle points of the sides and three auxiliary points in the orthogonal direction of each of the sides.
Bisector lines and intersection in the circumcenter of the triangle.
Different stages of the creation of a beehive structure with the aid of tessellations.
Creating a regular hexagon that works as the start of the tessellation.
Creating two contiguous hexagons to the starting one. These hexagons are derived from the middle points of some of the sides of the initial hexagon.
Once the contiguous hexagons are obtained, function
Alternative to step in
Examples of different fractals produced with the functions of the LearnGeom package. The examples obtained with
First seven iterations of the Sierpinski triangle.
First three first iterations of the Koch's curve.
First five first iterations of the Koch's as obtained with
A modificaction of the first five iterations of the Koch's (
A modificaction of the first five iterations of the Koch's (
A modificaction of the first five iterations of the Koch's (
Examples of use of the functions
Example of use of the function
Example of use of the function
Example of use of the function
Example of use of the function
Example of use of the function
Example of use of the function
The basic functions available in the LearnGeom R package to create geometric objects and the parameters that must be used to precisely define these objects. The third column refers to the geometric object that is created by each of the functions, which is also the class that the functions assign to their outputs.


























Short description of all the parameters available in the basic functions of the LearnGeom R package.











...  Ordered list of points to build the polygon 






Information contained in each of the possible objects that are produced by the basic functions. As it is shown in the table, the outputs of these functions are basically a vector or a matrix which contain the points that make the geometric object or the parameters that define the object unambiguously.














