I'm trying to use a Euclidean formula. I need x2 and y2 to be the inner [1] and [2] indeces of all the lists nested in blue_points respectively, but it doesn't do that. I am trying to make the Euclidean distance compute points from blue_points with the point1 list, then determine if it is less than or greater than/equal to so the program can return it as True or False respectively.
import math
# [ID, X coordinate, Y coordinate]
blue_points = [[30, 536254.99137, 3659453.06343],
[33, 536721.584912, 3659162.97207],
[50, 535807.099324, 3659576.92825],
[112, 536827.131371, 3657913.01245],
[117, 536473.254082, 3659433.57702],
[120, 536196.9844, 3658713.72722],
[127, 536387.547701, 3658527.70015],
[133, 537397.838429, 3659554.48657],
[144, 537715.931243, 3658625.59997],
[164, 538367.648437, 3658867.34288],
[172, 537112.662366, 3657921.28957],
[173, 536418.315024, 3658715.47946],
[209, 538096.28422, 3658514.93514],
[211, 538077.87716, 3658138.39337],
[223, 536220.396985, 3659243.54161],
[242, 536102.087002, 3658703.61054],
[244, 536968.755886, 3659409.42857],
[246, 535996.903591, 3658705.08691],
[275, 538078.165429, 3659022.35547],
[303, 535999.885405, 3658521.91524]]
# [ID, X coordinate,Y coordinate]
point1 = [1, 1073706.744,3658967.925]
neighbor_points = [] # Empty list to store values.
for point2 in blue_points:
if (math.sqrt(((point2[1] - point1[1]) ** 2) + ((point2[2] - point1[2]) ** 2))): # Euclidean distance formula.
neighbor_points.append(point2) # Add points to empty list.
print(point2[1:3]) # Print to check if indeces are correct.
x1 = point1[1]
y1 = point1[2]
x2 = blue_points[1]
y2 = blue_points[2]
distance = math.sqrt((neighbor_points[1] - point1[1]) ** 2) + ((neighbor_points[2] - point1[2]) ** 2)
def identify_neighbor(point1, point2):
if (distance < 536000):
print(distance)
print("True.")
return True
else:
print(distance)
print("False")
return False
neighbors = []
for point in blue_points:
if (math.sqrt(((neighbor_points[1] - point1[1]) ** 2) + ((neighbor_points[2] - point1[2]) ** 2))):
neighbors.append(point)
print(point[0])
identify_neighbor(point1, point2)