diff --git a/vector-light.lua b/vector-light.lua index 07a024a..40160f5 100644 --- a/vector-light.lua +++ b/vector-light.lua @@ -24,7 +24,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ]]-- -local sqrt, cos, sin = math.sqrt, math.cos, math.sin +local sqrt, cos, sin, atan2 = math.sqrt, math.cos, math.sin, math.atan2 local function str(x,y) return "("..tonumber(x)..","..tonumber(y)..")" @@ -120,6 +120,10 @@ local function trim(maxLen, x, y) return x * s, y * s end +local function angleTo(x,y, u,v) + return atan2(y - (v or 0), x - (u or 0)) +end + -- the module return { str = str, @@ -149,5 +153,6 @@ return { perpendicular = perpendicular, project = project, mirror = mirror, - trim = trim + trim = trim, + angleTo = angleTo, }