Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

find the center point of coordinate 2d array c#

Is there a formula to average all the x, y coordinates and find the location in the dead center of them.

I have 100x100 squares and inside them are large clumps of 1x1 red and black points, I want to determine out of the red points which one is in the middle.

I looked into line of best fit formulas but I am not sure if this is what I need.

Sometimes all the red will be on one side, or the other side. I want to essentially draw a line then find the center point of that line, or just find the center point of the red squares only. based on the 100x100 grid.

like image 219
Vans S Avatar asked Oct 11 '12 13:10

Vans S


People also ask

How do you find the center of a 2d array?

Simply average separately the x coordinates and the y coordinates, the result will be the coordinates of the "center".

How do you find the center of a set of points?

To get the center of a set of points, we can add all the elements of the list and divide that sum with the length of the list so that result could be the center of the corresponding axes.

How do you find the center of a matrix?

Simple Approach:Iterate two loops, find all half diagonal sums and then check all sums are equal to the center element of the matrix or not. If any one of them is not equal to center element Then print “No” Else “Yes”.


1 Answers

List<Point> dots = new List<Point>();
int totalX = 0, totalY = 0;
foreach (Point p in dots)
{
    totalX += p.X;
    totalY += p.Y;
}
int centerX = totalX / dots.Count;
int centerY = totalY / dots.Count;
like image 169
MrFox Avatar answered Sep 21 '22 12:09

MrFox