On the image above there is some geometrical pattern. Model a distance is known. Points are not in model distance strictly.

I want to:
- calculate each point quality (real distance between points is not
a) the better point fits to pattern better quality coeficient it should have (I’ve tried to take distance and 45deg angle) - eliminate wrong points (I’ve marked it with red) – it’s connected with pattern quality computing
What I’ve tried so far:
- Take each point with each other
- Calculate distance and angle between them
- Take only points neighbour to current point (which distance is between
a - deltaanda + delta - Quality is realDistance/modelDistance * realAngle/modelAngle
Why it failed:
- Good points quality was strongly decreased with bad points in neighbourhood
- If bad point has only one neighbour and the distance and angle was ok its quality was ok.
So the question is: what is the best algorithm to calculate points quality in this case, and fill pattern. Pattern should be filled by averaging position of element taking in account neighbours positions. The best answer will be pseudocode or code or reference to some known algorithm which can be helpful in this case.
Question is a little bit related with my previous question Filling rectangle with points pattern but the filling could not be done with wrong quality points.
If the error/distortion of the points does not get bigger when you go from left to right or top to bottom (i.e. the average distance
abetween neighbouring good points is known exactly enough), you can try the following:[0,a[ x [0,a[by taking the remainder of x and y coordinates when dividing through a (generating Qi). Thus the good points will more or less be mapped onto one point.Rwith the closest neighbours (e.g. sum up1/distancefor all distances to other points Qj, j≠ i, and choose the one with maximal sum).If the point R (with the closest neighbours) has a coordinate close to 0 or a (i.e. R is close to the border of the square
[0,a[ x [0,a[), you better start from the beginning and adda/2to the corresponding coordinate (of each Pi) before computing the remainder, in order to bring the point R more to the center of the square. (Or you manage to compute the minimal distance of the different possibilities of leaving the square[0,a[ x [0,a[on one side and come back into it on the opposite side.)