I have two lists
available_points = [[2,3], [4,5], [1,2], [6,8], [5,9], [51,35]]
and
solution = [[3,5], [2,1]]
I'm trying to pop a point in available_points
and append it to solution
for which the sum of euclidean distances from that point, to all points in the solution
is the greatest.
So, I would get this
solution = [[3,5], [2,1], [51,35]]
I was able to select the initial 2 furthest points like this, but not sure how to proceed.
import numpy as np
from scipy.spatial.distance import pdist, squareform
available_points = np.array([[2,3], [4,5], [1,2], [6,8], [5,9], [51,35]])
D = squareform(pdist(available_points)
I_row, I_col = np.unravel_index(np.argmax(D), D.shape)
solution = available_points[[I_row, I_col]]
which gives me
solution = array([[1, 2], [51, 35]])
An ellipse is "the set of all points in a plane such that the sum of the distances from two fixed points (foci) is constant".
The distance between the two points is defined as follows: d i s t ( a , b ) = s i n ( a + b ) × c o s ( a − b ) Your task is to determine the sum of the distances between all the points, where the first distance is greater than the second. Input format. First line: denoting the number of points on a line.
The distance between two points is called the length of the line segment. Segments having the same length are called congruent segments. We can calculate the distance between two points by drawing a line using a ruler.
√(0−x)2+(0−y)2=√x2+y2. Hence the distance between the origin and the point P is √x2+y2.
You can use cdist
-
In [1]: from scipy.spatial.distance import cdist
In [2]: max_pt=available_points[cdist(available_points, solution).sum(1).argmax()]
In [3]: np.vstack((solution, max_pt))
Out[3]:
array([[ 3, 5],
[ 2, 1],
[51, 35]])
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