Compare commits
3 Commits
574d9dc6b1
...
e7ef96bbcf
Author | SHA1 | Date |
---|---|---|
Arthur Moore | e7ef96bbcf | |
Arthur Moore | ff3a325b37 | |
Arthur Moore | 20492634d8 |
|
@ -71,28 +71,46 @@ function vector_as_unit(vector) = vector / vector_magnitude(vector);
|
|||
*/
|
||||
function atanv(vector) = atan2(vector.y, vector.x);
|
||||
|
||||
/**
|
||||
* @brief Affine transformation matrix for 2d rotation on the X,Y plane.
|
||||
* @param angle The angle to rotate things by
|
||||
* @returns an Affine transformation matrix for use with `multmatrix()`
|
||||
*/
|
||||
function affine_rotation(angle) = [
|
||||
[cos(angle), 0, sin(angle), 0],
|
||||
function _affine_rotate_x(angle_x) = [
|
||||
[1, 0, 0, 0],
|
||||
[0, cos(angle_x), -sin(angle_x), 0],
|
||||
[0, sin(angle_x), cos(angle_x), 0],
|
||||
[0, 0, 0, 1]
|
||||
];
|
||||
|
||||
function _affine_rotate_y(angle_y) = [
|
||||
[cos(angle_y), 0, sin(angle_y), 0],
|
||||
[0, 1, 0, 0],
|
||||
[-sin(angle), 0, cos(angle), 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 for 2d translation on the X,Y plane.
|
||||
* @param vector 2d Vector to translate by.
|
||||
* @returns an Affine transformation matrix for use with `multmatrix()`
|
||||
* @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_translation(vector) = [
|
||||
[1, 0, 0, vector.y],
|
||||
[0, 1, 0, 0],
|
||||
[0, 0, 1, vector.x],
|
||||
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 equivalent of `translate`
|
||||
* @param vector @see `translate`
|
||||
* @returns An affine transformation matrix for use with `multmatrix()`
|
||||
*/
|
||||
function affine_translate(vector) = [
|
||||
[1, 0, 0, vector.x],
|
||||
[0, 1, 0, vector.y],
|
||||
[0, 0, 1, vector.z],
|
||||
[0, 0, 0, 1]
|
||||
];
|
||||
|
||||
|
@ -118,39 +136,21 @@ module sweep_rounded(width=10, length=10) {
|
|||
];
|
||||
// These contain the translations, but not the rotations
|
||||
// OpenSCAD requires this hacky for loop to get accumulate to work!
|
||||
first_translation = affine_translation(path_points[0]);
|
||||
first_translation = affine_translate([path_points[0].y, 0,path_points[0].x]);
|
||||
affine_translations = concat([first_translation], [
|
||||
for (i = 0, a = first_translation;
|
||||
i < len(path_vectors);
|
||||
a=a * affine_translation(path_vectors[i]), i=i+1)
|
||||
a * affine_translation(path_vectors[i])
|
||||
a=a * affine_translate([path_vectors[i].y, 0, path_vectors[i].x]), i=i+1)
|
||||
a * affine_translate([path_vectors[i].y, 0, path_vectors[i].x])
|
||||
]);
|
||||
|
||||
// Affine matrix to rotate around X axis
|
||||
rot_x = 90;
|
||||
x_matrix = [
|
||||
[1, 0, 0, 0],
|
||||
[0, cos(rot_x), -sin(rot_x), 0],
|
||||
[0, sin(rot_x), cos(rot_x), 0],
|
||||
[0, 0, 0, 1]
|
||||
];
|
||||
|
||||
// Affine matrix to rotate around Z axis
|
||||
z_rot = 90;
|
||||
z_matrix = [
|
||||
[cos(z_rot), -sin(z_rot), 0, 0],
|
||||
[sin(z_rot), cos(z_rot), 0, 0],
|
||||
[0, 0, 1, 0],
|
||||
[0, 0, 0, 1]
|
||||
];
|
||||
|
||||
// Bring extrusion to the xy plane
|
||||
affine_matrix = z_matrix * x_matrix;
|
||||
affine_matrix = affine_rotate([90, 0, 90]);
|
||||
|
||||
walls = [
|
||||
for (i = [0 : len(path_vectors) - 1])
|
||||
affine_matrix * affine_translations[i]
|
||||
* affine_rotation(atanv(path_vectors[i]))
|
||||
* affine_rotate([0, atanv(path_vectors[i]), 0])
|
||||
];
|
||||
|
||||
union()
|
||||
|
@ -161,8 +161,7 @@ module sweep_rounded(width=10, length=10) {
|
|||
children();
|
||||
|
||||
// Rounded Corners
|
||||
multmatrix(walls[i]
|
||||
*x_matrix*x_matrix*x_matrix *z_matrix*z_matrix*z_matrix*z_matrix)
|
||||
multmatrix(walls[i] * affine_rotate([-90, 0, 0]))
|
||||
rotate_extrude(angle = 90, convexity = 4)
|
||||
children();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue