# CS190C: Spring 2009
# FirstName LastName
# Problem Set 3, Problem 2
from ps3_09_p2_lib import * #import helper functions provided
def distance(p, q):
return 0 #return distance
#write code
def closest(points, p):
return [5,5] #return closest point
#write code
def nearest_neighbors(points):
return [[0,0], [5,5]] #return pair of points
#write code
if __name__ == '__main__':
# Below is an example on how to use all functions;
# use it after all functions have been tested, but consider other
# sequences using your function as well
# Create a list of 100 random points
myPoints = random_points(50, 2)
# Save the points to a file
save_points(myPoints, "points.txt")
# Plot the points
show_points(myPoints, (0,1,0))
# Create three extra points
pointA = [1.0, 0.0]
pointB = [1.0, 1.0]
pointC = [0.0, 0.0]
# Print the distance between two points
print "The distance between", pointA, "and", pointB,"is:", distance(pointA, pointB)
# Find the point in myPoints closest to point B
closeToB = closest(myPoints, pointB);
print "The point closes to", pointB, "is:", closeToB
# Find the nearest neighbors in myPoints
pointX, pointY = nearest_neighbors(myPoints)
print "The nearest neighbors are:", pointX, "and", pointY