python - Find points furthest away from each other in array -
i have 5 points x,y coordinates , have allowed x,y offset. can apply offset each point move both positively , negatively. means there 4 possible locations each point, after applying allowed displacements.
import numpy np import matplotlib.pyplot plt # xy data 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 4 possible offset combinations each of 5 points xy_offset = [] 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') xy in xy_offset: plt.scatter(*zip(*xy)) plt.show() the original points shown below in black, 4 possible new positions colored (same color 4 offset positions each point):
i need find combination of 5 "new" displaced positions points, such sum of distance between each point , closest 1 maximized.
okay ... approximate solution algorithm ...
- compute centroid of existing points.
- for each point's 4 choices, choose 1 farthest centroid.
- compute total distance; first approximation.
- for each point in set, check effect of moving each of other 3 choices. if of gives better total distance, change position.
- repeat step 4 until there no further changes.

Comments
Post a Comment