Research Ideas and Outcomes : R Package

Corresponding author: Ángel SerranoAroca (angel.serrano@ucv.es)
Received: 03 Apr 2018  Published: 05 Apr 2018
© 2018 Álvaro BrizRedón, Ángel SerranoAroca
This is an open access article distributed under the terms of the Creative Commons Attribution License (CC BY 4.0), which permits unrestricted use, distribution, and reproduction in any medium, provided the original author and source are credited.
Citation: BrizRedón Á, SerranoAroca Á (2018) Novel pedagogical tool for simultaneous learning of plane geometry and R programming. Research Ideas and Outcomes 4: e25485. https://doi.org/10.3897/rio.4.e25485

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.
Mathematics Education; Geometry Education; Computational Thinking; Programming Language; R package
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 (https://www.rproject.org) and after typing install.packages(LearnGeom) in the program console to install the developed LearnGeom R package. The LearnGeom Rpackage can also be found as a github repository in
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 CoordinatePlane allows the user to plot an empty coordinate plane with customizable limits for the X and Y axis. For example, CoordinatePlane(5, 5, 5, 5) can be typed to set a coordinate plane in the range [5,5] x [5,5], which is the one used for most of the examples included in the paper. Once a coordinate plane is started, different geometric objects can be created and plotted on it. The basic geometric objects that can be utilised in this version of the package are five: points, segments, arcs, lines and polygons.
All of them can be plotted in the coordinate plane with function Draw, and the appropriate use of the methods that R offers can lead to different mathematical concepts and many kind of geometric problems. A point can be created by simply defining a twodimensional vector in R, e.g., P = c(0,0) for the usual origin of coordinates. This definition is also used for the creation of a geometric vector to determine a direction in the plane. The coincidence of both definitions also exists if classical mathematical notations are followed. Therefore, it should not be a source of confusion for the user.
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 CreateSegmentPoints and CreateSegmentAngle functions of the package. A line, as a segment, can be defined from two points, or from a point and an angle. Moreover, there is a standard combination of parameters to characterize every line in the plane: the slope and the intercept. For this reason, CreateLinePoints and CreateLineAngle functions return a twodimensional vector that contains the slope and intercept of the line, regardless of the way it is defined. The use of the pair slopeintercept has a problem with vertical lines, which are parallel to Y axis. In the case that the user defines a line of this kind, with any of the two available functions, the returning object will be a string twodimensional vector. It will include the word "Inf" for the first position (infinite slope) and the constant Xvalue for the line in the second (as a character).
An arc is simply a part of a circumference, or even the circumference itself. The CreateArcAngle function allows the user to make an arc from a circumference with four parameters to choose: the center of the circumference, the radius of the circumference and the two angles, from 0 to 360 degrees that determine the part of the circumference to be plotted. Another possibility to create an arc in the plane consists of connecting two points. The CreateArcPointsDist function allows the user to connect any two given points in the plane by an arc. Of course, there are many (infinite) arcs that pass through every two points in a plane. The parameter radius fixes a radius for the arc to be built. If the selected radius is smaller than half the distance between the points, the problem has no solution and no arc is produced (a message is shown on the screen to inform the user).
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 CreatePolygon function admits any finite number of points to produce a polygon, which corresponds to the definition of a polygon as a list of points. It is important to introduce the points in a certain order to get the desired output because the same combination of points can lead to different figures. In order to make a polygon without selfintersections, the points must be passed to the function following a clockwise (or counterclockwise) direction. Moreover, this function includes a procedure to detect collinearity between the points, which makes the function to show the message "Some of the inserted points are collinear. This could lead to a defective polygon" when this occurs. If the user is interested in building a regular polygon given its center, number of sides and side length, the CreateRegularPolygon function can do it.
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 Draw function is programmed to be able to accept all kind of geometric objects as a parameter. This fact seems to be essential to understand geometric ideas because of providing the user a quick and intuitive tool to easily visualize while programming. The only visible difference among the different geometric objects and Draw function occurs with polygons. This function adds, only for polygons, the option of using two colours and the possibility of inserting labels at each of the points of the object.
As a summary, Table
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.
Function  Parameters  Geometric object 
CreateArcAngles  C, r, angle1, angle2, direction  Arc 
CreateArcPointsDist  P1, P2, r, choice, direction  
CreateLineAngle  P, angle  Line 
CreateLinePoints  P1, P2  
CreatePolygon  List of points  Polygon 
CreateRegularPolygon  n, C, l  
CreateSegmentAngle  P, angle, l  Segment 
CreateSegmentPoints  P1, P2 
A brief explanation of the parameters which are associated to each of these functions can be found in Table
Short description of all the parameters available in the basic functions of the LearnGeom R package.
Function  Parameters description 
CreateArcAngles  C  Center for the circumference which generates the arc 
r  Radius for the circumference which generates the arc  
angle1  Angle (0360) from which the arc starts  
angle2  Angle (0360) at which the arc arrives  
direction  Clockwise or anticlockwise direction to properly define the arc  
CreateArcPointsDist  P1  Point 1 to be joined by an arc to point 2 
P2  Point 2 to be joined by an arc to point 1  
r  Radius for the arc being built  
choice  Integer which allows the user to choose every arc from two possibilities  
direction  Clockwise or anticlockwise direction to properly define the arc  
CreateLineAngle  P  Point through which the line passes 
angle  Angle (0360) that the line must form with Xaxis  
CreateLinePoints  P1  Point 1 to be joined by a line to point 2 
P2  Point 2 to be joined by a line to point 1  
CreatePolygon  ...  Ordered list of points to build the polygon 
CreateRegularPolygon  n  Number of sides for the polygon 
C  Center for regular polygon  
l  Side length for the polygon  
CreateSegmentAngle  P  Starting point for the segment being built 
angle  Angle (0360) that the segment must form with Xaxis  
l  Length for the segment  
CreateSegmentPoints  P1  Point 1 to be joined by a segment to point 2 
P2  Point 2 to be joined by a segment to point 1 
Table
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.
Geometric object  Data type  Object fields 
Arc  Vector  X – Xcoordinate for the center of the arc 
Y – Ycoordinate for the center of the arc  
r – radius of the arc  
angle1 – Angle (0º360º) from which the arc starts  
angle2 – Angle (0º360º) at which the arc arrives  
dir – 1 for anticlockwise direction, 2 for clockwise  
Line  Vector  slope – Slope of the line 
intercept – Intercept (Yaxis cut) of the line  
Polygon  Matrix  X – Xcoordinates for the points that are part of the polygon 
Y – Ycoordinates for the points that are part of the polygon  
Segment  Matrix  X – Xcoordinates for the two points that form the segment 
Y – Ycoordinates for the two points that form the segment 
Fig.
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.
Fig.
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.
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 Line to it. This also applies to the other three geometric objects. However, this is not the use of the package we would expect for a new user of it. The rest of this paper contains multiple examples of use of some functions of the package that have not been mentioned yet and several applications which are possible to perform by combining classical geometric problems, different programming techniques and all the functions included in the package. These applications are thus classified into three categories according to their level of difficulty: basic, intermediate and advanced.
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 Polygon.
The use of the affine transformations functions included in the package can be seen in Fig.
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 needs the definition of a line to be used as the axis of reflection, which can be built by the CreateLinePoints or CreateLineAngle functions (Fig.
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, k, in the SimilarPolygon package function. This parameter allows the user to create a polygon similar to the original one, which can be a contraction (k < 1) or an expansion (k > 1), altering the size of the polygon without changing its shape (Fig.
Translation simply represents the movement of a polygon in the direction of vector v, conserving the angles and lengths of the initial polygon (Fig.
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.
ShearedPolygon shares parameter k with SimilarPolygon, as both transformations enable a change in the size of the polygon. However, the transformation produced by ShearedPolygon does not conserve the shape of the object. The direction parameter has two possible values, horizontal and vertical, which allow the deformation of the initial polygon in the two directions of the plane (Fig.
On the other hand, the function Homothety can also produce an enlargement or reduction of a polygon in relation to a point of the plane called the center of the homothety. The function contains an option to display all the lines that connect the points of the original and the transformed polygons passing through the center (Fig.
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 CreatePolygon function is used for this step. Letters A, B and C are used to represent the three points of the triangle. It is also convenient to calculate and visualize the middle points of the triangle sides. The MidPoint function of this package can perform this task (see Fig.
Partial results during the process of finding the circumcenter of the triangle of points (1,0), (0,1) and (1,0).
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.
Different stages of the creation of a beehive structure with the aid of tessellations.
In order to obtain two hexagons that are contiguous to the initial one, Hexa0 can be translated in the direction determined by its center and the middle point of the segment that joins points 1 and 6 (for Hexa1) and the one that joins 2 and 3 (for Hexa2) (see Fig.
The final step requires the use of the Tessellation function with the right separation parameter (see Fig.
The GetMap function of the RgoogleMaps package gives users the possibility to treat geometric objects over a plane that represents a piece of the world we live in. The zoom parameter ranges from 0 to 21, depending on the location, allowing the user to visualize big pictures of the world but also little details of some buildings.
The function CoordinateImage of this package works as CoordinatePlane. However, in this case, it is capable of setting the axis and the grid over an image obtained from Google Maps. As an illustration, the approximation of the British coast with a polygon can be performed, which is a problem that is connected to the posterior definition of fractal
> library(RgoogleMaps)
> ima < GetMap(c(53.404059,3.351493), zoom = 5, maptype = "satellite")
> ima < ima[[4]]
> CoordinateImage(10, 10, 10, 10, ima)
> S < SelectPoints(30)
> Draw(S, c("transparent","white"))
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
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 italics) is a possible approach to produce the first six iterations of the Sierpinski triangle. It is necessary to create a function Sierpinski to call it recursively during the triangle construction:
> x_min < 6; x_max < 6; y_min < 6; y_max < 6
> CoordinatePlane(x_min, x_max, y_min, y_max)
> n < 3; C < c(0,0); l < 5
> Tri < CreateRegularPolygon(n, C, l)
> it < 6
> Sierpinski < function(Tri, it){
if (it==1){
Draw(Tri,"black")
}
if (it>1){
Sierpinski(CreatePolygon(Tri[1,], MidPoint(Tri[1,],Tri[2,]), MidPoint(Tri[1,],Tri[3,])), it1)
Sierpinski(CreatePolygon(Tri[2,] ,MidPoint(Tri[1,],Tri[2,]), MidPoint(Tri[2,],Tri[3,])), it1)
Sierpinski(CreatePolygon(Tri[3,] ,MidPoint(Tri[1,],Tri[3,]), MidPoint(Tri[2,],Tri[3,])), it1)
}
}
> Sierpinski(Tri, it)
The R code included just displayed is basically the same one that contains the function Sierpinski of the package. This function allows users to visualize the first iterations of the fractal avoiding the difficulty of building it (see Fig.
Examples of different fractals produced with the functions of the LearnGeom package. The examples obtained with FractalSegment show how minimal modifications of the parameters can lead to very different curves.
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 FractalSegment function, available in this package, allows the user to create an infinity number of curves whose construction is based on these steps. The user can experiment with cut, angle and f parameters to achieve all kind of fractals (starting from iteration it = 0). The cut parameter allows a nonequal division of the segments at step 1, however, the angle parameter allows the user to build more than an equilateral triangle at step 2. Finally, the f parameter, which is a positive number, produces a length enlargement or a reduction for the new segments at each iteration. Users are free to try these parameters and produce some fractals like those shown in figures Fig.
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 Star, which can be utilised to represent very different starlike objects as another application of the LOGO turtle also taken from
Examples of use of the functions Duopoly and Star.
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.