From 48140e507f2f0b385603d0b743ab2b0050670af5 Mon Sep 17 00:00:00 2001 From: Revar Desmera Date: Tue, 26 Mar 2019 23:22:38 -0700 Subject: [PATCH] Added path_length() --- paths.scad | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/paths.scad b/paths.scad index f665342..e64cb28 100644 --- a/paths.scad +++ b/paths.scad @@ -91,6 +91,21 @@ function simplify3d_path(path, eps=1e-6) = concat( ); +// Function: path_length() +// Usage: +// path3d_length(path) +// Description: +// Returns the length of the path. +// Arguments: +// path = The list of points of the path to measure. +// Example: +// path = [[0,0], [5,35], [60,-25], [80,0]]; +// echo(path_length(path)); +function path_length(path) = + len(path)<2? 0 : + sum([for (i = [0:len(path)-2]) norm(path[i+1]-path[i])]); + + // Function: path2d_regular_ngon() // Description: // Returns a 2D open counter-clockwise path of the vertices of a regular polygon of `n` sides.