From f215f27f9f5f9b38b2a29cce72cefe70b426d6af Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Thu, 2 May 2019 10:22:31 +0800 Subject: [PATCH] always to a vect --- src/m_translation.scad | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/m_translation.scad b/src/m_translation.scad index 23dfdc7d..5a199a72 100644 --- a/src/m_translation.scad +++ b/src/m_translation.scad @@ -1,6 +1,15 @@ -function m_translation(v) = [ - [1, 0, 0, v[0]], - [0, 1, 0, v[1]], - [0, 0, 1, v[2]], - [0, 0, 0, 1] -]; \ No newline at end of file +function _to_vect(v) = + len(v) == 3 ? v : ( + len(v) == 2 ? [v[0], v[1], 0] : ( + len(v) == 1 ? [v[0], 0, 0] : [v, 0, 0] + ) + ); + +function m_translation(v) = + let(vt = _to_vect(v)) + [ + [1, 0, 0, vt[0]], + [0, 1, 0, vt[1]], + [0, 0, 1, vt[2]], + [0, 0, 0, 1] + ]; \ No newline at end of file