Here is an example of how you can do that based on two criteria - distance between vertices and the angle you described above:
import numpy as np
def reduce_polygon(polygon, angle_th=0, distance_th=0):
angle_th_rad = np.deg2rad(angle_th)
points_removed = [0]
while len(points_removed):
points_removed = list()
for i in range(0, len(polygon)-2, 2):
v01 = polygon[i-1] - polygon[i]
v12 = polygon[i] - polygon[i+1]
d01 = np.linalg.norm(v01)
d12 = np.linalg.norm(v12)
if d01 < distance_th and d12 < distance_th:
points_removed.append(i)
continue
angle = np.arccos(np.sum(v01*v12) / (d01 * d12))
if angle < angle_th_rad:
points_removed.append(i)
polygon = np.delete(polygon, points_removed, axis=0)
return polygon
example:
from matplotlib import pyplot as plt
from time import time
tic = time()
reduced_polygon = reduce_polygon(original_polygon, angle_th=5, distance_th=4)
toc = time()
plt.figure()
plt.scatter(original_polygon[:, 0], original_polygon[:, 1], c='r', marker='o', s=2)
plt.scatter(reduced_polygon[:, 0], reduced_polygon[:, 1], c='b', marker='x', s=20)
plt.plot(reduced_polygon[:, 0], reduced_polygon[:, 1], c='black', linewidth=1)
plt.show()
print(f'original_polygon length: {len(original_polygon)}\n',
f'reduced_polygon length: {len(reduced_polygon)}\n'
f'running time: {round(toc - tic, 4)} secends')
Produces the following result:
