diff --git a/README.md b/README.md index b2abf61a..37066e49 100644 --- a/README.md +++ b/README.md @@ -243,6 +243,10 @@ These examples incubate dotSCAD and dotSCAD refactors these examples. See [examp - [bauer_spiral](https://openhome.cc/eGossip/OpenSCAD/lib2x-bauer_spiral.html) - [fibonacci_lattice](https://openhome.cc/eGossip/OpenSCAD/lib2x-fibonacci_lattice.html) +### Util + +- [lerp](https://openhome.cc/eGossip/OpenSCAD/lib2x-lerp.html) + ### Voxel - [vx_bezier](https://openhome.cc/eGossip/OpenSCAD/lib2x-vx_bezier.html) diff --git a/docs/lib2x-lerp.md b/docs/lib2x-lerp.md new file mode 100644 index 00000000..e05d9e7b --- /dev/null +++ b/docs/lib2x-lerp.md @@ -0,0 +1,17 @@ +# lerp + +Linear interpolate the vector v1 to v2. + +**Since:** 2.5 + +## Parameters + +- `v1` : Minimum value of random number range. Default to 0. +- `v2` : Maximum value of random number range. Default to 1. +- `amt` : The amount of interpolation. Some value between 0.0 and 1.0. + +## Examples + + use ; + + assert(lerp([0, 0, 0], [100, 100, 100], 0.5) == [50, 50, 50]); \ No newline at end of file diff --git a/src/util/lerp.scad b/src/util/lerp.scad index c11bca41..e1fe65be 100644 --- a/src/util/lerp.scad +++ b/src/util/lerp.scad @@ -1,3 +1,13 @@ +/** +* lerp.scad +* +* @copyright Justin Lin, 2020 +* @license https://opensource.org/licenses/lgpl-3.0.html +* +* @see https://openhome.cc/eGossip/OpenSCAD/lib2x-lerp.html +* +**/ + function lerp(v1, v2, amt) = let( v = v2 - v1,