Mô phỏng thuật toán Định lý Pick (diện tích lưới)

Pick's Theorem · Nhóm: Hình học

Định lý Pick (diện tích lưới) (Pick's Theorem), nhóm Hình học.

Mã Python

def pick_area(poly):
    # poly: integer-coordinate vertices
    B = I = 0
    for (x, y) in lattice_points(poly):
        if on_boundary(x, y, poly):
            B += 1
        elif inside(x, y, poly):
            I += 1
        else:
            pass  # outside
    # Pick theorem
    return I + B / 2 - 1

Mở trang để xem mô phỏng từng bước và xuất slide bài giảng.