mirror of
https://github.com/kennetek/gridfinity-rebuilt-openscad.git
synced 2024-12-22 14:53:25 +00:00
Update affine_rotate to support all axes.
This commit is contained in:
parent
574d9dc6b1
commit
20492634d8
1 changed files with 28 additions and 10 deletions
|
@ -71,18 +71,36 @@ function vector_as_unit(vector) = vector / vector_magnitude(vector);
|
||||||
*/
|
*/
|
||||||
function atanv(vector) = atan2(vector.y, vector.x);
|
function atanv(vector) = atan2(vector.y, vector.x);
|
||||||
|
|
||||||
/**
|
function _affine_rotate_x(angle_x) = [
|
||||||
* @brief Affine transformation matrix for 2d rotation on the X,Y plane.
|
[1, 0, 0, 0],
|
||||||
* @param angle The angle to rotate things by
|
[0, cos(angle_x), -sin(angle_x), 0],
|
||||||
* @returns an Affine transformation matrix for use with `multmatrix()`
|
[0, sin(angle_x), cos(angle_x), 0],
|
||||||
*/
|
|
||||||
function affine_rotation(angle) = [
|
|
||||||
[cos(angle), 0, sin(angle), 0],
|
|
||||||
[0, 1, 0, 0],
|
|
||||||
[-sin(angle), 0, cos(angle), 0],
|
|
||||||
[0, 0, 0, 1]
|
[0, 0, 0, 1]
|
||||||
];
|
];
|
||||||
|
|
||||||
|
function _affine_rotate_y(angle_y) = [
|
||||||
|
[cos(angle_y), 0, sin(angle_y), 0],
|
||||||
|
[0, 1, 0, 0],
|
||||||
|
[-sin(angle_y), 0, cos(angle_y), 0],
|
||||||
|
[0, 0, 0, 1]
|
||||||
|
];
|
||||||
|
|
||||||
|
function _affine_rotate_z(angle_z) = [
|
||||||
|
[cos(angle_z), -sin(angle_z), 0, 0],
|
||||||
|
[sin(angle_z), cos(angle_z), 0, 0],
|
||||||
|
[0, 0, 1, 0],
|
||||||
|
[0, 0, 0, 1]
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Affine transformation matrix equivalent of `rotate`
|
||||||
|
* @param angle_vector @see `rotate`
|
||||||
|
* @details Equivalent to `rotate([0, angle, 0])`
|
||||||
|
* @returns An affine transformation matrix for use with `multmatrix()`
|
||||||
|
*/
|
||||||
|
function affine_rotate(angle_vector) =
|
||||||
|
_affine_rotate_z(angle_vector.z) * _affine_rotate_y(angle_vector.y) * _affine_rotate_x(angle_vector.x);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Affine transformation matrix for 2d translation on the X,Y plane.
|
* @brief Affine transformation matrix for 2d translation on the X,Y plane.
|
||||||
|
@ -150,7 +168,7 @@ module sweep_rounded(width=10, length=10) {
|
||||||
walls = [
|
walls = [
|
||||||
for (i = [0 : len(path_vectors) - 1])
|
for (i = [0 : len(path_vectors) - 1])
|
||||||
affine_matrix * affine_translations[i]
|
affine_matrix * affine_translations[i]
|
||||||
* affine_rotation(atanv(path_vectors[i]))
|
* affine_rotate([0, atanv(path_vectors[i]), 0])
|
||||||
];
|
];
|
||||||
|
|
||||||
union()
|
union()
|
||||||
|
|
Loading…
Reference in a new issue