예제 #1
0
 def addThisPoint(self, x, y):
     # Display this point
     self.canvas.create_oval(x - RADIUS, y - RADIUS, x + RADIUS, y + RADIUS)
     # Add this point to self.points list
     i = -1
     p = self.points.append([x, y])
     if len(self.points) >= 2:
         i = i + 1
         d = NearestPoints.distance(self.points[i][0], self.points[i][1],
                                    self.points[i + 1][0],
                                    self.points[i + 1][1])
         # for t in range(len(self.points) - 1):
         for t in self.points:
             # if NearestPoints.distance(x, y, self.points[t + 1][0], self.points[t + 1][1]) < d:
             if NearestPoints.distance(x, y, t[0], t[1]) < d:
                 d = NearestPoints.distance(x, y, t[0], t[1])
                 k = t[0], t[1]
                 p1, p2 = p, k
             p1, p2 = NearestPoints.nearestPoints(self.points)
             self.canvas.delete("line")
             self.canvas.create_line(self.points[p1][0],
                                     self.points[p1][1],
                                     self.points[p2][0],
                                     self.points[p2][1],
                                     tags="line")
 def addThisPoint(self, x, y):
     # Display this point
     self.canvas.create_oval(x - RADIUS, y - RADIUS,
         x + RADIUS, y + RADIUS)
     # Add this point to self.points list
     self.points.append([x, y]) 
     if len(self.points) > 2:
         p1, p2 = NearestPoints.nearestPoints(self.points)
         self.canvas.delete("line") 
         self.canvas.create_line(self.points[p1][0], 
             self.points[p1][1], self.points[p2][0], 
             self.points[p2][1], tags = "line")
 def addThisPoint(self, x, y):
     # Display this point
     self.canvas.create_oval(x - RADIUS, y - RADIUS,
         x + RADIUS, y + RADIUS)
     # Add this point to self.points list
     self.points.append([x, y]) 
     if len(self.points) > 2:
         p1, p2 = NearestPoints.nearestPoints(self.points)
         self.canvas.delete("line") 
         self.canvas.create_line(self.points[p1][0], 
             self.points[p1][1], self.points[p2][0], 
             self.points[p2][1], tags = "line")
 def addThisPoint(self, x, y):
     # display this point
     self.canvas.create_oval(x - radius, y - radius, x + radius, y + radius)
     # add this point to self.points list
     self.points.append([x, y])
     if len(self.points) > 2:
         p1, p2 = NearestPoints.nearestPoints(self.points)
         self.canvas.delete("line")
         self.canvas.create_line(self.points[p1][0],
                                 self.points[p1][1],
                                 self.points[p2][0],
                                 self.points[p2][1],
                                 tags="line")
         self.shortestDist.set(
             NearestPoints.distance(self.points[p1][0], self.points[p1][1],
                                    self.points[p2][0], self.points[p2][1]))
예제 #5
0
def main():
    numberOfPoints=eval(input("Enter number of points: "))

    points=[]
    for i in range(numberOfPoints):
        point=2*[0]
        # point=2*[0]
        point[0],point[1]=eval(input("Enter coordinates separated by a comma: "))
        points.append(point)

    p1,p2,min=NearestPoints.nearestPoints(points)

    print("The closest two points are (",
          points[p1][0],",",points[p1][0],")  (",
          points[p2][0],",",points[p2][1],")")
    print("The distance is",min)
예제 #6
0
def main():
    numberOfPoints = eval(input("Enter the number of points: "))

    # Create a list to store points
    points = []
    print("Enter", numberOfPoints, "points:", end='')
    for i in range(numberOfPoints):
        point = 2 * [0]
        point[0], point[1] = \
            eval(input("Enter coordinates separated by a comma: "))
        points.append(point)

    # p1 and p2 are the indices in the points list
    p1, p2 = NearestPoints.nearestPoints(points)

    # Display result
    print("The closest two points are (" + str(points[p1][0]) + ", " +
          str(points[p1][1]) + ") and (" + str(points[p2][0]) + ", " +
          str(points[p2][1]) + ")")
def main():
    numberOfPoints = eval(input("Enter the number of points: "))

    # Create a list to store points
    points = []
    print("Enter", numberOfPoints, "points:", end = '')
    for i in range(numberOfPoints):
        point = 2 * [0]
        point[0], point[1] = \
            eval(input("Enter coordinates separated by a comma: "))
        points.append(point)

    # p1 and p2 are the indices in the points list
    p1, p2 = NearestPoints.nearestPoints(points)  

    # Display result
    print("The closest two points are (" +
        str(points[p1][0]) + ", " + str(points[p1][1]) + ") and (" +
        str(points[p2][0]) + ", " + str(points[p2][1]) + ")")
예제 #8
0
def main():
    numberOfPoints = eval(input("점의 개수를 입력하세요: "))

    # 점을 저장하기 위한 리스트를 생성한다.
    points = []
    print(numberOfPoints, "개 점의 위치를 입력하세요:", end='')
    for i in range(numberOfPoints):
        point = 2 * [0]
        point[0], point[1] = \
            eval(input("콤마로 분리하여 점의 좌표값을 입력하세요: "))
        points.append(point)

    # p1과 p2는 points 리스트의 인덱스이다.
    p1, p2 = NearestPoints.nearestPoints(points)

    # 결과를 출력한다.
    print(
        "가장 가까운 두 점은 (" + str(points[p1][0]) + ", " + str(points[p1][1]) +
        ")과/와 (" + str(points[p2][0]) + ", " + str(points[p2][1]) + ")",
        "입니다.")
예제 #9
0
파일: Q1.py 프로젝트: noahcou/CSET-Work
def main():
    numberOfPoints = eval(input("Eneter the number of coordinates: "))

    # create a list to store points
    points = list()

    print(f"Enter {numberOfPoints} points")
    # collect all inputs
    for _ in range(0, numberOfPoints):
        point = 2 * [0]
        point[0], point[1] = eval(
            input("Enter coordinates seperated by comma: "))
        points.append(point)

    # get the two nearest
    p1, p2 = NearestPoints.nearestPoints(points)

    # display results
    print(
        f"The closest two points are ({str(points[p1][0])}, {str(points[p1][1])}) and ({str(points[p2][0])}, {str(points[p2][1])})"
    )