CALCULATING AREAS OF CONVEX POLYGONS USING MACHINE
LEARNING
Mantilla Manzano, John Sebastian * johns.mantillam@konradlorenz.edu.co Neira Parra, Nataly Phawllyn † natalyp.neirap@konradlorenz.edu.co Vargas Arevalo, Juan Sebastian ‡ juans.vargasa@konradlorenz.edu.co Abstract In the current era of computational problem-solving, a paradigm shift is taking place: traditional sequential programming is giving way to machine learning approaches. Translating classical geometric problems into this new paradigm is essential for applications in artificial intelligence. This article addresses the open problem of calculating the area of convex polygons using machine learning techniques. It explores two main approaches: image-based classification and numerical regression, applying various models such as Support Vector Machines, linear and polynomial regressions, and neural networks. The study compares the performance, advantages, and limitations of each method, concluding that neural networks are the most effective solution when the task is framed as a regression problem.
1
Introduction One of the fundamental aspects of mathematics is the study of geometric figures. The principal objectives in geometry, classification and measurement, have been developed over more than two thousand years, since the Greeks laid the foundation of mathematics by modeling the abstract world through geometry. Determining the area of certain figures is now wellestablished and straightforward. Today, numerous formulas and approaches are available for calculating the area of various types of figures, including polygons. However, the relevance of this topic persists. While classical geometry offers well-established methods for calculating areas, the increasing demands of automation and artificial intelligence require these methods to be reimagined in a computational context. As artificial intelligence and automation advance, challenges arise, especially in improving the efficiency of classical processes such as calculating the areas of convex polygons (CPs). Various approaches to this problem have been *Facultad de Matem´aticas e Ingenier´ıa, Fundaci´on Universitaria Konrad Lorenz †Facultad de Matem´aticas e Ingenier´ıa, Fundaci´on Universitaria Konrad Lorenz ‡Facultad de Matem´aticas e Ingenier´ıa, Fundaci´on Universitaria Konrad Lorenz explored, including algorithms in sequential programming like the Shoelace Formula [Rak19], the Triangulation Method [Bur23], and the Monte Carlo Method [Kal08]. Nevertheless, translating this problem into the realm of machine learning (ML) has proven to be complex. Several challenges arise when implementing this problem in a ML context:
• Data Representation and Complexity: CPs are defined
by their number of vertices; however, both the number and the positions of these vertices vary, complicating their representation as input data.
• Precision and Generalization Issues: ML models typ-
ically approximate functions, whereas precise measurements require high accuracy. Managing accumulated errors poses a significant challenge.
• Overfitting on Polygon Types: CPs exhibit a wide vari-
ety of shapes. Models trained predominantly on regular polygons may fail to generalize effectively across different polygon shapes.
In this paper, the challenges in developing a ML model for calculating the areas of CPs using neural networks are discussed, and potential solutions are proposed and analyzed.
2
Definitions and Background The problem is restricted by defining a planar polygon as convex if it contains all line segments connecting any pair of its points. Another useful definition describes it as ”the boundary of a convex set” [Wei24a]. Based on this definition, CPs can be constructed using a convex hull derived from a set of points S in N-dimensions. The convex hull is defined as the intersection of all convex sets that contain S. For n points p1, p2,···, pn the CP is expressed as:
C =
(
n ∑ i=1 λipi | n ∑ i=1 λi = 1,λi ≥0 , ∀i
)
(1)
This method of constructing CPs is widely used in computational algorithms, with a complexity order of O(n2) as noted in [Wei24b]. However, more efficient methods are now
Calculating Areas of Convex Polygons Using Machine Learning available, such as Scipy.Spatial.ConvexHull in Python. This method relies on Qhull, a computational geometry library that implements the Quickhull algorithm with an improved complexity order of O(nlogn) [Bar96]. These computational advancements provide a solid foundation for constructing the training dataset, as explored further in this work. With a clear understanding of CPs, attention is now directed to existing algorithms for calculating their areas, which include:
• Triangulation Method: This method divides a polygon
into n −2 non-overlapping triangles and calculates the area of each triangle using the following formula: At = 1
2 |x1(y2 −y3)+x2(y3 −y1)+x3(y1 −y2)|
(2)
This method has a computational complexity of order of O(n).
• Monte Carlo Method: This method estimates the area
of a polygon probabilistically by generating random points within a bounding box surrounding the polygon. The area is then calculated as:
Ap = Abox × N NT
(3)
where N is the number of points inside the polygon, and NT is the total number of points.
The computational complexity is O(NT · n), where n is the number of vertices. This method is suitable for approximate solutions, but its accuracy depends on NT.
• Shoelace Method: Also known as the Gauss area for-
mula, this direct computational method calculates the area by summing the products of the x-coordinates of vertices with the y-coordinates of the next vertices and subtracting the reverse order:
Ap = 1
2
n ∑ i=1 (xiyi+1 −yixi+1)
(4)
This method has a computational complexity of O(n), where n is the number of vertices in the polygon. Its efficiency and simplicity make it the most suitable choice for constructing the training dataset.
Although the algorithms described are highly effective for specific, well-structured data, they align with traditional programming approaches, which often lack the adaptability needed for more dynamic and complex data-driven challenges. ML offers a paradigm shift by providing powerful tools to address such challenges.
As stated in [EA24], in today’s technological landscape, ML ability to learn from data, adapt to new information, and uncover hidden patterns makes it an invaluable asset.
However, limited research exists on the application of ML to calculate the areas of CPs, leaving it as an open problem for further exploration. This challenge has been presented in programming contests to encourage the transition from sequential algorithms to ML frameworks. Nonetheless, related studies, such as Feature Selection Based on Orthogonal Constraints and Polygon Area [ZZao24], have highlighted the potential of ML in geometric computations. To better understand ML, a brief review is presented below. Machine Learning ML is a way of modeling systems with the objective of predicting outcomes or uncovering patterns from data. It represents a new programming paradigm by learning and adapting from a dataset, without requiring explicit reprogramming. Unlike traditional programming, ML models are nondeterministic, allowing them to adapt to new information. ML approaches can be broadly categorized into two types: Supervised Learning: Models are trained on labeled datasets, where input-output pairs are known. The goal is to learn a mapping from inputs to outputs to make predictions. Unsupervised Learning: Models analyze unlabeled data to identify patterns or structures, such as clustering similar data points. There are many models used in ML, including linear regression, polynomial regression, K-means clustering, Support Vector Machines (SVMs), and Neural Networks (NNs),etc. For the purpose of this work, we will focus on defining SVMs and NNs.
• SVMs are supervised learning models that separate data
into classes using a hyperplane in a high-dimensional space.
While primarily used for classification tasks, SVMs can also solve regression problems, making them versatile in various applications.
• NNs are computational models inspired by the structure
of the brain, consisting of layers of interconnected ”neurons” that process and learn patterns in data. There are different types of neural networks, including: Feedforward Neural Networks: These are the simplest type of NNs, where information flows in one direction—from input to output. Convolutional Neural Networks: Primarily used for image data.
Recurrent Neural Networks: Designed for sequential data, these are ideal for tasks involving time-series or sequences. Multilayer Perceptrons: These are commonly used for structured data. They can model complex relationships between inputs and outputs.
In the following section, the ways in which ML can address these challenges are examined, with specific approaches utilizing SVMs and NNs.
3
Proposed Methodology The problem addressed in this work involves calculating the area of any CPs. This task must consider certain limita-
Pask´ın Matem´atico Vol. 7 No 2 (2025) 09-14.
11
tions, which depend directly on the type of solution pursued. Factors such as the number of vertices, their positions on the Cartesian plane, and the format of the input data play a critical role in defining these constraints.
For any proposed solution, it is important to divide the process into two phases: the creation of the training set and modeling the solution.Two common approaches for addressing both phases with supervised learning are discussed in this paper.
3.1
Classifying the CPs by the area The first approach focuses on classifying CPs into approximate area values by rounding to the nearest integer of the actual value. To achieve this, the classification range is restricted. In this case, integer values from 0 to 25 square units are considered, and the CPs are constrained to fit within a 5×5 square in the first quadrant of the Cartesian plane. Furthermore, the number of vertices is limited to 10, with the vertices provided as coordinates.
The Training Dataset The training dataset consists of various types of CPs and their actual areas. Since this task involves supervised learning, random CPs are generated using the convex hull of a set S of random points - with discrete uniform distribution-, as described in Section 2(1). This method ensures that the resulting polygons are convex. After identifying the convex hull points as the vertices of the CPs, the area was calculated using the Shoelace method(4), utilizing the information derived from the convex hull. The CPs, along with their vertices and respective areas, are then represented as images for classification purposes.
In the first approach, a training dataset of CPs was a set of images, where each CP is plotted on a grid of 255 pixels. The lines connecting consecutive vertices are painted in gray, ready for rendering, as illustrated in Figure 1. These images can be produced either with or without displaying the grid. It is crucial that the lines of the CP are thicker than the grid lines to enhance contrast in the image.
The generated images were organized into different folders, each labeled with the corresponding area value rounded to the nearest integer. The folder labeled ”zero” is included, as it accounts for polygons where all vertices are collinear. The first model was trained on a dataset of 20.000 images of random CPs, ensuring that there were no null or duplicated data. The metadata for each image included the rounded area of each CP.
Model Architecture The model used in this approach is a convolutional neural network (CNN). (file modeloCNN.ipynb [Var25]) The input layer contains as many neurons as there are pixels in the generated image, while the output layer consists of one neuron for each of the 26 possible area values. The output layer uses Figure 1: Examples of convex polygons (CPs) generated from the training dataset. The leftmost figure shows a collinear polygon, which results in zero area. The rightmost figure represents a CP with an area rounded to 25 U2.
a Softmax activation function to produce the probability that the CP represented in the image corresponds to a specific area value.
The hidden layers employ the ReLU activation function to introduce non-linearity into the model, enabling it to learn complex patterns and relationships effectively. Metrics and Considerations The model was trained using 80% of the generated dataset over 20 epochs, while the remaining 20% was used for validation. As shown in Figure 2, the training loss decreased steadily, and the validation loss followed a similar trend with mild fluctuations, indicating a reasonable fit to the training data. However, as illustrated in Figure 3, the validation accuracy was highly unstable across epochs—oscillating between near-zero and occasional peaks around 45%—while the training accuracy gradually increased to approximately 40%. This mismatch suggests that, despite a decreasing validation loss, the model struggled to generalize well to unseen data. Figure 2: Training and validation metrics across 20 epochs. Shows the evolution of the loss function for both training and validation sets.
Calculating Areas of Convex Polygons Using Machine Learning Figure 3: Training and validation metrics across 20 epochs. Shows training and validation accuracy.
The model struggled to predict the area of CPs plotted in different locations on the grid but with the same area value. Additionally, it had difficulty predicting the area of polygons with values close to 25. The differences in metrics when using the two types of images (with or without a grid) were negligible.
The suboptimal results can be attributed to the use of a CNN for this type of image. CNNs simplify the image to detect patterns, but the training set images are already simplistic, leaving limited scope for pattern extraction. The next step is to consider reframing the problem as a regression task rather than a classification task.
3.2
Regression Approach As stated in [Bis06], ”The goal of regression is to predict the value of one or more continuous target variables t given the value of a D- dimensional vector x of input variables.” In this case, the area is a continuous target variable, and other characteristics of the CPs can be used as the input vector. In addition to the vertices, features such as the lengths of the edges, the mass center, or the geometric center can be considered.
Regression in ML can be implemented using various methods, including linear regression, polynomial regression, SVMs, and NNs. The choice of method depends on the results obtained and the format of the training dataset. The Training Dataset The training dataset for this approach was initially constructed in a manner similar to the previous dataset, although the representation differs(file auto crear poli.py [Var25]). In this model, the lengths of the edges are considered as the primary parameters. These values provide greater flexibility by removing the constraints that were previously imposed on the model. Specifically, the CPs are no longer required to be confined to a specific area; however, the number of vertices must remain limited to 10.
This dataset contains 40,000 CPs with a random number of vertices. Since this is a supervised learning approach, the area is calculated using the Shoelace Theorem. However, a more precise value is now considered.
Model Architecture The regression approach provides more flexibility, allowing for a wider selection of models. In this section, seven machine learning models were constructed and tested using the same dataset([Var25]). Choosing the most suitable model depends on the specific requirements of the programmer and the characteristics of the problem being addressed. For the different models, methods implemented in the sklearn library were used. Specifically, DecisionTreeRegressor was employed for the decision tree model, while RandomForestRegressor was used for the random forest model, both with only the random state parameter fixed. Additionally, KNeighborsRegressor was used for the KMeans model, with the n neighbors parameter set to five. It was not necessary to scale the data for any of these models. From the same library, LinearRegression was used for the linear regression model and polynomial regression with the key difference that, for the last one, the input data was transformed into polynomial features using PolynomialFeatures with degree two. This transformation introduced non-linear characteristics into the regression. Both models were trained using data in its normal scale, unlike the previous models. For the SVM model, the SVR (Support Vector Regression) method was used with the Radial Basis Function kernel. The training data for this model wasn’t scaled. Finally, for the NNs model, the MLPRegressor method was employed with 3000 hidden layers and a maximum of 30,000 iterations, with the random state parameter fixed. The training dataset was also used without scaling. Metrics and Considerations Each model was trained using the same dataset described above, with 80% of the data used for training and the remaining 20% for testing. Their performance was evaluated based on two key metrics: Mean Squared Error (MSE) and accuracy. MSE is particularly important in regression tasks because it penalizes larger errors more heavily, providing a precise measure of prediction quality. Accuracy, in this context, refers to how close the predicted area is to the actual area within an acceptable margin. The results of each one are presented in a table 1.
Even though the performance of each approach is satisfactory, linear regression and decision trees obtained the highest MSE values(2.5-3.48) and the lowest accuracy(86%-86.6%), indicating that they produced less reliable predictions and were more prone to large deviations from the true area. This suggests that these models are less suitable for the specific
Pask´ın Matem´atico Vol. 7 No 2 (2025) 09-14.
13
characteristics and complexity of the polygon area estimation problem.
In contrast, the neural network (NN) regression model, designed to estimate the area of convex polygons, achieved the best overall performance, with a Mean Squared Error of 0.92 and an accuracy of 91.8%. This strong performance is due to the model’s ability to learn complex, non-linear relationships between the input features—specifically, a numerical vector containing the edge lengths and the number of edges—and the corresponding polygon area. Unlike simpler models, the NN can extract hidden patterns from this structured input, enabling precise estimations even without access to the original vertex coordinates or visual representations. Model
MSE
Accuracy Decision tree
3.48
86.6 %
Random forest
1.68
90 %
KMeans
1.9
89.3 %
Linear regression
2.5
86 %
Polynomial regression
1.7
91.3 %
SVM
1.2
91.6 %
Neural network regression
0.92
91.8 %
Table 1: Table that compares metrics between various models Therefore, it is essential to examine the details of the NN model and its results more closely. To assess the model’s generalization ability and detect potential overfitting, performance metrics were computed on both the training and test sets.
By comparing the performance metrics between these two sets, we can evaluate how well the model generalizes to unseen data. A significant gap between the training and test metrics would indicate potential overfitting, meaning the model memorized patterns from the training set rather than learning generalizable features. In this case, the results showed a difference of -0.015 in MSE and 0.002 in R2 (the coefficient of determination, indicating the proportion of variance in the dependent variable explained by the model), suggesting that the model maintains similar performance across both datasets.
While these small differences indicate that overfitting is not evident, additional validation techniques, such as cross-validation or evaluation on an independent dataset, would further confirm the model’s ability to generalize effectively.
4
Discussion The interpretation of the regression results can be framed in the context of the Universal Approximation Theorem (UAT), which, as stated in [Cyb89], ensures that a feedforward neural network with at least one hidden layer and a sufficient number of neurons can approximate any continuous function on compact subsets of Rn, assuming the use of appropriate activation functions.
However, while the UAT affirms the expressive capacity of NNs to model complex functions—such as the relationship between geometric features and the area of CPs, it does not provide any guidance on selecting the optimal architecture, number of neurons, or training parameters to achieve such approximation in practice. This limitation highlights a key challenge: NNs are theoretically powerful but practically dependent on well-informed design choices and rigorous evaluation.
In this context, the relevance of selecting appropriate performance metrics, constructing unbiased datasets, and applying overfitting detection strategies becomes evident. These considerations were central to both approaches explored in this study.
The following section summarizes the key findings of this study and reflects on the comparative effectiveness of the classification and regression approaches.
5
Conclusions This study compared two supervised ML approaches for estimating the area of CPs: a classification model based on convolutional neural networks using image inputs, and a regression model using numerical features derived from the geometry of the CPs.
In the classification approach, performance was evaluated primarily through accuracy. Although the validation loss decreased consistently, the accuracy remained low and unstable across epochs, indicating limited generalization. This outcome is likely due to the low representational richness of the input images. Overfitting was assessed by analyzing training and validation curves. The regression approach, in contrast, yielded more robust and stable results. The use of both MSE and accuracy allowed for a more comprehensive evaluation. Among the tested models, the NN’s achieved the best performance, with the lowest MSE and highest accuracy. The small differences between training and test metrics, including MSE and R2, suggest good generalization and low overfitting. The synthetic training dataset was designed to avoid duplication and preserve geometric variability, which contributed to model reliability. Despite these findings, the exclusive use of synthetic data with fixed constraints, such as a maximum of 10 vertices and uniform sampling, limits the applicability of the models. The absence of noise, irregular shapes, or topological diversity may restrict generalization to more complex or real-world data. Future work should explore expanded datasets, include additional geometric descriptors, and evaluate performance on non-convex or noisy polygons, potentially incorporating geometric deep learning techniques.
References [Rak19] Ochilbek Rakhmanov, A new approach (extra vertex) and generalization of Shoelace Algorithm usage in convex polygon (Pointin-Polygon) (2019). Available on arXiv.
[Bur23] John Burkardt, Geometry: Triangles and Polygons Mathematical Programming, Florida State University, Tallahassee, FL, 2023. Lecture notes, Florida State University.
Calculating Areas of Convex Polygons Using Machine Learning [Kal08] Jonathan Kaldor, Monte Carlo Methods and Area Estimates, Cornell University, Ithaca, NY, 2008. Lecture slides, Cornell University.
[Wei24a] Eric W. Weisstein, Convex Polygon, Wolfram Research, Inc., Champaign, IL, 2024. From MathWorld–A Wolfram Web Resource.
[Wei24b] , Convex Hull, Wolfram Research, Inc., Champaign, IL, 2024. From MathWorld–A Wolfram Web Resource. [Bar96] C. Bradford and Dobkin Barber David P. and Huhdanpaa, The Quickhull Algorithm for Convex Hulls, The Geometry Center, Minneapolis, MN, 1996. Qhull documentation. [EA24] EMB Academy, AI Revolution: Machine Learning Outpaces Traditional Coding (2024). Published on EMB Academy’s official website.
[ZZao24] Zhenxing Zhang and others, Feature Selection Based on Orthogonal Constraints and Polygon Area, arXiv abs/2402.16026 (2024). Available online.
[Bis06] Christopher M. Bishop, Pattern Recognition and Machine Learning, Springer, New York, 2006.
[Cyb89] George Cybenko, Approximation by superpositions of a sigmoidal function, Mathematics of Control, Signals and Systems 2 (1989), no. 4, 303–314. Open version available online. [Var25] Juan Sebasti´an Vargas, AreaRegionConvexa:
Repositorio en GitHub,
2025.
https://github.com/NataPhawllyn/ AreaRegionConvexa.
Acknowledgments We would like to express our heartfelt gratitude to Professor John A. Arredondo for his invaluable inspiration and support throughout this project. His guidance has been instrumental in shaping our understanding and approach. We are particularly thankful for introducing us to the fascinating problem we are currently addressing. His unwavering encouragement and insightful feedback have been essential in pushing us to explore new perspectives and enhance our research. We are truly grateful for his dedication and mentorship. About the authors:
Sebastian Mantilla is a mathematics student, interested in numbers, discret maths and algebras, and their connections to problem-solving. He enjoys swimming and traveling, and aspires to pursue an academic career in mathematics. Nataly Neira is in the final semester of a Mathematics degree, with interests in numerical relativity and machine learning. She enjoys reading,the theater, and exploring the city, and aspires to travel more and spend time living abroad. Juan Vargas is a mathematician interested in AI models and searching algorithms. Juan loves reading and playing tennis. He aspires to become a referent on IA industry.
Cita: Mantilla Manzano, John Sebastián, Neira Parra, Nataly Phawllyn, Vargas Arévalo, Juan Sebastián (2025), Calculating areas of convex polygons using machine learning, Fundación Universitaria Konrad Lorenz, p. N. https://repositorio.konradlorenz.edu.co/handle/001/6717