Finding the middle point of the "most populated" area in a set of points? I'm working on a game-related application, and I'm trying to find the middle point of the most populated area in my map.
Example:
Positions (format [x, y]) :

[48, 49]
[51, 50]
[49, 50]
[51, 49]
[49, 48]
[130, 150]
[129, 148]

Excepted output : [50, 50] or something close enough like [49, 51], [51, 50]

To create this algorithm I've access to all entities position (X/Y)
I've tried by creating a position using X average and Y average but it's not what i'm looking for (using example values output would have been [75, 75] or something like this and not [50, 50] as excepted)
Here is an example image:
Red dot: Entities
Green dot: Position i'm looking for

Thanks for reading and for your help!
What you are looking for is called cluster analysis or a clustering algorithm. It's a topic studied in unsupervised machine learning, so there's not necessarily a single &quot;best&quot; algorithm that exists (rather, there are different methods which are meant to optimize for different metrics). For example, do you want your clusters to all be similar size? Do you want a fixed number of clusters, or a variable number of clusters? Different answers to these questions result in different algorithms, so you will have to do some research (or try out directly) the different clustering algorithms available. For example, one of the classic algorithms is called k-means clustering.
Once you find the clusters, you can take the average of the points in the biggest cluster to solve your problem.
You don't have to implement the algorithm yourself -- many machine learning libraries (scikit-learn, Pytorch, ...) have out-of-the-box clustering procedures that you can try out and see what they look like for your dataset.