Created
January 16, 2012 08:02
-
-
Save danmackinlay/1619688 to your computer and use it in GitHub Desktop.
pure python bezier smoothing for matplotlib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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