Added degrees, radians and rot2_z() to maths.scad.

This commit is contained in:
Chris Palmer 2020-07-06 12:43:24 +01:00
parent f047ac27f7
commit e4d93366fa
2 changed files with 14 additions and 1 deletions

View File

@ -5283,17 +5283,21 @@ Maths utilities for manipulating vectors and matrices.
|:--- |:--- |
| ```angle_between(v1, v2)``` | Return the angle between two vectors |
| ```augment(m)``` | Augment a matrix by adding an identity matrix to the right |
| ```degrees(radians)``` | Convert degrees to radians |
| ```euler(R)``` | Convert a rotation matrix to a Euler rotation vector. |
| ```identity(n, x = 1)``` | Construct an arbitrary size identity matrix |
| ```invert(m)``` | Invert a matrix |
| ```nearly_zero(x)``` | True if x is close to zero |
| ```radians(degrees)``` | Convert radians to degrees |
| ```reverse(v)``` | Reverse a vector |
| ```rot2_z(a)``` | Generate a 2x2 matrix to rotate around z |
| ```rot3_z(a)``` | Generate a 3x3 matrix to rotate around z |
| ```rotate(a, v)``` | Generate a 4x4 rotation matrix, ```a``` can be a vector of three angles or a single angle around ```z```, or around axis ```v``` |
| ```rowswap(m, i, j)``` | Swap two rows of a matrix |
| ```scale(v)``` | Generate a 4x4 matrix that scales by ```v```, which can be a vector of xyz factors or a scalar to scale all axes equally |
| ```solve(m, i = 0, j = 0)``` | Solve each row ensuring diagonal is not zero |
| ```solve_row(m, i)``` | Make diagonal one by dividing the row by it and subtract from other rows to make column zero |
| ```sqr(x)``` | Square x |
| ```transform(v, m)``` | Apply 4x4 transform to a 3 vector by extending it and cropping it again |
| ```transform_points(path, m)``` | Apply transform to a path |
| ```translate(v)``` | Generate a 4x4 translation matrix, ```v``` can be ```[x, y]```, ```[x, y, z]``` or ```z``` |

View File

@ -20,7 +20,10 @@
//
//! Maths utilities for manipulating vectors and matrices.
//
function sqr(x) = x * x;
function sqr(x) = x * x; //! Square x
function radians(degrees) = degrees * PI / 180; //! Convert radians to degrees
function degrees(radians) = radians * 180 / PI; //! Convert degrees to radians
function translate(v) = let(u = is_list(v) ? len(v) == 2 ? [v.x, v.y, 0] //! Generate a 4x4 translation matrix, ```v``` can be ```[x, y]```, ```[x, y, z]``` or ```z```
: v
@ -63,6 +66,12 @@ function rot3_z(a) = //! Generate a 3x3 matrix to rotate around z
[ s, c, 0],
[ 0, 0, 1] ];
function rot2_z(a) = //! Generate a 2x2 matrix to rotate around z
let(c = cos(a),
s = sin(a))
[ [ c, -s],
[ s, c] ];
function scale(v) = let(s = is_list(v) ? v : [v, v, v]) //! Generate a 4x4 matrix that scales by ```v```, which can be a vector of xyz factors or a scalar to scale all axes equally
[
[s.x, 0, 0, 0],