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.
Simply average separately the x coordinates and the y coordinates, the result will be the coordinates of the "center".
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.
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”.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With