Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
pure python bezier smoothing for matplotlib
"""
For http://stackoverflow.com/q/5255932
"""
def tangent_interpolate(index, x_array, y_array, dist=0.5):
before_index = max(index - 1, 0)
after_index = min(index + 1, len(x_array))
chord_vector_x = x_array[after_index] - x_array[before_index]
chord_vector_y = y_array[after_index] - y_array[before_index]
if dist>0:
next_point_x_dist = x_array[after_index] - x_array[index]
else:
next_point_x_dist = x_array[index] - x_array[before_index]
scale_factor = float(next_point_x_dist)/chord_vector_x
return x_array[index] + dist * scale_factor * chord_vector_x,\
y_array[index] + dist * scale_factor * chord_vector_y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment