From e56e9c1207c2e5ffd82b46bdb561e02ff94c8a2b Mon Sep 17 00:00:00 2001 From: Lars Mueller Date: Tue, 2 Feb 2021 15:43:55 +0100 Subject: [PATCH] Add vector.interpolate --- vector.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/vector.lua b/vector.lua index bef0486..59c502b 100644 --- a/vector.lua +++ b/vector.lua @@ -115,6 +115,12 @@ metatable.__sub = subtract metatable.__mul = multiply metatable.__div = divide +--+ linear interpolation +--: ratio number from 0 (all the first vector) to 1 (all the second vector) +function interpolate(v, other_v, ratio) + return add(multiply(v, 1 - ratio), multiply(other_v, ratio)) +end + function norm(v) local sum = 0 for _, c in pairs(v) do