mirror of
https://github.com/nophead/NopSCADlib.git
synced 2025-08-14 03:13:59 +02:00
Added degrees, radians and rot2_z() to maths.scad.
This commit is contained in:
@@ -5283,17 +5283,21 @@ Maths utilities for manipulating vectors and matrices.
|
|||||||
|:--- |:--- |
|
|:--- |:--- |
|
||||||
| ```angle_between(v1, v2)``` | Return the angle between two vectors |
|
| ```angle_between(v1, v2)``` | Return the angle between two vectors |
|
||||||
| ```augment(m)``` | Augment a matrix by adding an identity matrix to the right |
|
| ```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. |
|
| ```euler(R)``` | Convert a rotation matrix to a Euler rotation vector. |
|
||||||
| ```identity(n, x = 1)``` | Construct an arbitrary size identity matrix |
|
| ```identity(n, x = 1)``` | Construct an arbitrary size identity matrix |
|
||||||
| ```invert(m)``` | Invert a matrix |
|
| ```invert(m)``` | Invert a matrix |
|
||||||
| ```nearly_zero(x)``` | True if x is close to zero |
|
| ```nearly_zero(x)``` | True if x is close to zero |
|
||||||
|
| ```radians(degrees)``` | Convert radians to degrees |
|
||||||
| ```reverse(v)``` | Reverse a vector |
|
| ```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 |
|
| ```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``` |
|
| ```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 |
|
| ```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 |
|
| ```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(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 |
|
| ```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(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 |
|
| ```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``` |
|
| ```translate(v)``` | Generate a 4x4 translation matrix, ```v``` can be ```[x, y]```, ```[x, y, z]``` or ```z``` |
|
||||||
|
@@ -20,7 +20,10 @@
|
|||||||
//
|
//
|
||||||
//! Maths utilities for manipulating vectors and matrices.
|
//! 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```
|
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
|
: v
|
||||||
@@ -63,6 +66,12 @@ function rot3_z(a) = //! Generate a 3x3 matrix to rotate around z
|
|||||||
[ s, c, 0],
|
[ s, c, 0],
|
||||||
[ 0, 0, 1] ];
|
[ 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
|
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],
|
[s.x, 0, 0, 0],
|
||||||
|
Reference in New Issue
Block a user