Skip to content

Instantly share code, notes, and snippets.

@jbush001
Created November 28, 2019 11:02
Show Gist options
  • Save jbush001/6e08a8b64e154f37cc31d3c0df0ae7a9 to your computer and use it in GitHub Desktop.
Save jbush001/6e08a8b64e154f37cc31d3c0df0ae7a9 to your computer and use it in GitHub Desktop.
function cubic_bezier(control_points, steps) = [
for (t = [0 : 1 / steps : 1]) [
for (i = [0:1])
pow(1 - t, 3) * control_points[0][i] + 3 * pow(1 - t, 2) * t * control_points[1][i]
+ 3 * (1 - t) * pow(t, 2) * control_points[2][i] + pow(t, 3) * control_points[3][i]
]
];
function bezier_path(points, steps) = [
for (a = [for (i = [0 : 3 : len(points) - 3])
cubic_bezier([for (j = [0:3]) points[i + j]], steps)]) for (b = a) b
];
module extrude_path(points, steps, height) {
linear_extrude(height=height) polygon(bezier_path(points, steps));
}
// Test
extrude_path([[-10, -10], [-5, -25], [15, -15], [10, -10], [15, -5], [15, 5], [10, 10], [5, 20], [-5, 20], [-10, 10]], 32, 10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment