tyl*_*ler -1 python area python-3.x
我正在做一个问题,我需要找到给定 3 组坐标的三角形面积
那么将数组转换为 (a1,b1) (a2,b2) (a3,b3) 中的对的逻辑是什么以及如何使用该顶点查找三角形的面积
这是我的代码
def getTriangleArea(x, y):
///What will be the code 
if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')
    x_count = int(input().strip())
    x = []
    for _ in range(x_count):
        x_item = int(input().strip())
        x.append(x_item)
    y_count = int(input().strip())
    y = []
    for _ in range(y_count):
        y_item = int(input().strip())
        y.append(y_item)
    result = getTriangleArea(x, y)
    fptr.write(str(result) + '\n')
    fptr.close()
Run Code Online (Sandbox Code Playgroud)
    三角形的面积,其中(x1,y1)为第 1 坐标,(x2,y2)为第 2 坐标,(x3,y3)为第 3 坐标。
Area = 1/2[x1(y2 - y3) + x2(y3 - y1) + x3(y1 - y2)]
Run Code Online (Sandbox Code Playgroud)
Area = 1/2[x1(y2 - y3) + x2(y3 - y1) + x3(y1 - y2)]
Run Code Online (Sandbox Code Playgroud)
输出
Area of points (2, 4), (3, -6), (7, 8) is 27 
Run Code Online (Sandbox Code Playgroud)