I have 5 points with x,y
coordinates and I also have an allowed x,y
offset. I can apply this offset to each point to move it both positively and negatively. This means that there are four possible locations for each point, after applying all allowed displacements.
import numpy as np
import matplotlib.pyplot as plt
# xy data for 5 points
xy = [[1929.39695287, 1579.6, 1548.0451124, 1561.47793473, 1053.18163361],
[2020.79329391, 1869.4327316, 1800.71748721, 2112.769, 1840.28]]
xy = zip(*xy)
# Define xy offset
offset = [201.8445, 202.9015]
# Create the 4 possible offset combinations for each of the 5 points
xy_offset = []
for pt in xy:
xy_offset.append([
[pt[0] + offset[0], pt[1] + offset[1]],
[pt[0] + offset[0], pt[1] - offset[1]],
[pt[0] - offset[0], pt[1] + offset[1]],
[pt[0] - offset[0], pt[1] - offset[1]]])
plt.scatter(*zip(*xy), c='k')
for xy in xy_offset:
plt.scatter(*zip(*xy))
plt.show()
The original points are shown below in black, with their 4 possible new positions colored (same color for the 4 offset positions for each point):
I need to find the combination of the 5 "new" displaced positions for all points, such that the sum of the distance between each point and the closest one is maximized.