欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

判断四个点是不是组成正方形

程序员文章站 2022-04-02 18:50:26
...

判断四个点是不是组成正方形

给出几组数,每组的第一行为横坐标,第二行为纵坐标。看其是否组成正方形

代码

#coding=utf-8
import sys
if __name__ == "__main__":
    # 读取第一行的n
    # n = int(sys.stdin.readline().strip())
    n=3
    ans = 0
    arr = [[0,0,2,2],[0,2,0,2],[0,1,5,6],[1,6,0,5],[0,0,7,7],[0,3,0,3]]
    # for i in range(2*n):
        # 读取每一行
        # line = sys.stdin.readline().strip()
        # 把每一行的数字分隔后转化成int列表
        # values = list(map(int, line.split()))
        # for v in values:
        #     ans += v
        #     arr.append(v)
        # arr.append(values)
    print(arr)
    i=0
    while i<len(arr)-1:
        print(arr[i])
        print(arr[i + 1])

        point0 = [arr[i][0],arr[i+1][0]]
        point1 = [arr[i][1], arr[i + 1][1]]
        point2 = [arr[i][2], arr[i + 1][2]]
        point3 = [arr[i][3], arr[i + 1][3]]

        len1 = ((point0[0] - point1[0]) ** 2 + (point0[1] - point1[1]) ** 2)
        len2 = ((point0[0] - point2[0]) ** 2 + (point0[1] - point2[1]) ** 2)
        len3 = ((point0[0] - point3[0]) ** 2 + (point0[1] - point3[1]) ** 2)
        len4 = ((point1[0] - point2[0]) ** 2 + (point1[1] - point2[1]) ** 2)
        len5 = ((point1[0] - point3[0]) ** 2 + (point1[1] - point3[1]) ** 2)
        len6 = ((point2[0] - point3[0]) ** 2 + (point2[1] - point3[1]) ** 2)
        arr2=[len1,len2 ,len3,len4,len5,len6]
        dict = {}
        for item in arr2:
            if item in dict.keys():
                dict[item] = dict[item]+1
            else:
                dict[item] = 1
        print(dict)
        if (len(dict)==2) and (dict[len1]==2 or dict[len1]==4):
            print('Yes')
        else:
            print('No')
        i = i + 2