mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-18 20:41:18 +02:00
refactor
This commit is contained in:
@@ -1,34 +1,25 @@
|
||||
use <../../__comm__/__to_ang_vect.scad>;
|
||||
|
||||
FINAL_ROW = [0, 0, 0, 1];
|
||||
function __m_rotation_q_rotation(a, v) =
|
||||
let(
|
||||
half_a = a / 2,
|
||||
axis = v / norm(v),
|
||||
s = sin(half_a),
|
||||
x = s * axis.x,
|
||||
y = s * axis.y,
|
||||
z = s * axis.z,
|
||||
w = cos(half_a),
|
||||
|
||||
x2 = x + x,
|
||||
y2 = y + y,
|
||||
z2 = z + z,
|
||||
uv = v / norm(v),
|
||||
s = sin(a / 2) * uv,
|
||||
w = sin(a) * uv,
|
||||
|
||||
xx = x * x2,
|
||||
yx = y * x2,
|
||||
yy = y * y2,
|
||||
zx = z * x2,
|
||||
zy = z * y2,
|
||||
zz = z * z2,
|
||||
wx = w * x2,
|
||||
wy = w * y2,
|
||||
wz = w * z2
|
||||
xx = 2 * s.x ^ 2,
|
||||
yy = 2 * s.y ^ 2,
|
||||
zz = 2 * s.z ^ 2,
|
||||
|
||||
xy = 2 * s.x * s.y,
|
||||
xz = 2 * s.x * s.z,
|
||||
yz = 2 * s.y * s.z
|
||||
)
|
||||
[
|
||||
[1 - yy - zz, yx - wz, zx + wy, 0],
|
||||
[yx + wz, 1 - xx - zz, zy - wx, 0],
|
||||
[zx - wy, zy + wx, 1 - xx - yy, 0],
|
||||
[0, 0, 0, 1]
|
||||
[1 - yy - zz, xy - w.z, xz + w.y, 0],
|
||||
[xy + w.z, 1 - xx - zz, yz - w.x, 0],
|
||||
[xz - w.y, yz + w.x, 1 - xx - yy, 0],
|
||||
FINAL_ROW
|
||||
];
|
||||
|
||||
function __m_rotation_xRotation(a) =
|
||||
@@ -37,7 +28,7 @@ function __m_rotation_xRotation(a) =
|
||||
[1, 0, 0, 0],
|
||||
[0, c, -s, 0],
|
||||
[0, s, c, 0],
|
||||
[0, 0, 0, 1]
|
||||
FINAL_ROW
|
||||
];
|
||||
|
||||
function __m_rotation_yRotation(a) =
|
||||
@@ -46,7 +37,7 @@ function __m_rotation_yRotation(a) =
|
||||
[c, 0, s, 0],
|
||||
[0, 1, 0, 0],
|
||||
[-s, 0, c, 0],
|
||||
[0, 0, 0, 1]
|
||||
FINAL_ROW
|
||||
];
|
||||
|
||||
function __m_rotation_zRotation(a) =
|
||||
@@ -55,7 +46,7 @@ function __m_rotation_zRotation(a) =
|
||||
[c, -s, 0, 0],
|
||||
[s, c, 0, 0],
|
||||
[0, 0, 1, 0],
|
||||
[0, 0, 0, 1]
|
||||
FINAL_ROW
|
||||
];
|
||||
|
||||
function __m_rotation_xyz_rotation(a) =
|
||||
@@ -67,5 +58,5 @@ function _m_rotation_impl(a, v) =
|
||||
[1, 0, 0, 0],
|
||||
[0, 1, 0, 0],
|
||||
[0, 0, 1, 0],
|
||||
[0, 0, 0, 1]
|
||||
FINAL_ROW
|
||||
] : (is_undef(v) ? __m_rotation_xyz_rotation(a) : __m_rotation_q_rotation(a, v));
|
@@ -5,11 +5,12 @@ function __m_scaling_to_3_elems_scaling_vect(s) =
|
||||
|
||||
function __m_scaling_to_scaling_vect(s) = is_num(s) ? [s, s, s] : __m_scaling_to_3_elems_scaling_vect(s);
|
||||
|
||||
FINAL_ROW = [0, 0, 0, 1];
|
||||
function _m_scaling_impl(s) =
|
||||
let(v = __m_scaling_to_scaling_vect(s))
|
||||
[
|
||||
[v.x, 0, 0, 0],
|
||||
[0, v.y, 0, 0],
|
||||
[0, 0, v.z, 0],
|
||||
[0, 0, 0, 1]
|
||||
FINAL_ROW
|
||||
];
|
@@ -1,3 +1,4 @@
|
||||
FINAL_ROW = [0, 0, 0, 1];
|
||||
function _m_shearing_impl(sx, sy, sz) =
|
||||
let(
|
||||
sx_along_y = sx[0],
|
||||
@@ -11,5 +12,5 @@ function _m_shearing_impl(sx, sy, sz) =
|
||||
[1, sx_along_y, sx_along_z, 0],
|
||||
[sy_along_x, 1, sy_along_z, 0],
|
||||
[sz_along_x, sz_along_y, 1, 0],
|
||||
[0, 0, 0, 1]
|
||||
FINAL_ROW
|
||||
];
|
@@ -5,11 +5,12 @@ function _to_3_elems_translation_vect(v) =
|
||||
|
||||
function _to_translation_vect(v) = is_num(v) ? [v, 0, 0] : _to_3_elems_translation_vect(v);
|
||||
|
||||
FINAL_ROW = [0, 0, 0, 1];
|
||||
function _m_translation_impl(v) =
|
||||
let(vt = _to_translation_vect(v))
|
||||
[
|
||||
[1, 0, 0, vt.x],
|
||||
[0, 1, 0, vt.y],
|
||||
[0, 0, 1, vt.z],
|
||||
[0, 0, 0, 1]
|
||||
FINAL_ROW
|
||||
];
|
Reference in New Issue
Block a user