I have a XY points list (trackP[][]) for car track, and i want to "smooth" it. Because in pymunk (and other physics engines) there is no more complex shapes than polys (or segments), in my opinion I need to interpolate data points, to remove sharp corners... How can I do that? I will need that knowledge to generate "Hill climb racing" track too (smooth track from set of points). My track at the moment (it is procedural generated from seed):track
EDIT: I've found an answer, it's chaikin's corner cutting algorithm. Below is my "fork" of code from here
def chaikins_corner_cutting(coords, refinements=5):
coords.insert(0,coords[len(coords)-1])
coords.append(coords[1])
coords = np.array(coords)
for _ in range(refinements):
L = coords.repeat(2, axis=0)
R = np.empty_like(L)
R[0] = L[0]
R[2::2] = L[1:-1:2]
R[1:-1:2] = L[2::2]
R[-1] = L[-1]
coords = L * 0.75 + R * 0.25
coords2 = coords.tolist()
for i in range(2**refinements):
coords2.pop(0)
i+=1
for i in range(2**refinements):
coords2.pop(len(coords2)-1)
return coords2