When working with polygons, one common task is calculating the length of its diagonals. Diagonals are line segments that connect…