From b11c5914b35f1b781f166cf99586958774b3e25d Mon Sep 17 00:00:00 2001 From: Chris Palmer Date: Tue, 15 Sep 2020 20:58:39 +0100 Subject: [PATCH] Added hyperbolic maths functions --- readme.md | 8 ++++++++ utils/maths.scad | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/readme.md b/readme.md index a1a33b8..28ee733 100644 --- a/readme.md +++ b/readme.md @@ -5420,7 +5420,13 @@ Maths utilities for manipulating vectors and matrices. | Function | Description | |:--- |:--- | | ```angle_between(v1, v2)``` | Return the angle between two vectors | +| ```argcosh(x)``` | inverse hyperbolic cosine | +| ```argcoth(x)``` | inverse hyperbolic cotangent | +| ```argsinh(x)``` | inverse hyperbolic sine | +| ```argtanh(x)``` | inverse hyperbolic tangent | | ```augment(m)``` | Augment a matrix by adding an identity matrix to the right | +| ```cosh(x)``` | hyperbolic cosine | +| ```coth(x)``` | hyperbolic cotangent | | ```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 | @@ -5433,9 +5439,11 @@ Maths utilities for manipulating vectors and matrices. | ```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 | +| ```sinh(x)``` | hyperbolic sine | | ```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 | +| ```tanh(x)``` | hyperbolic tangent | | ```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``` | diff --git a/utils/maths.scad b/utils/maths.scad index 3a78627..0130d60 100644 --- a/utils/maths.scad +++ b/utils/maths.scad @@ -24,6 +24,14 @@ 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 sinh(x) = (exp(x) - exp(-x)) / 2; //! hyperbolic sine +function cosh(x) = (exp(x) + exp(-x)) / 2; //! hyperbolic cosine +function tanh(x) = sinh(x) / cosh(x); //! hyperbolic tangent +function coth(x) = cosh(x) / sinh(x); //! hyperbolic cotangent +function argsinh(x) = ln(x + sqrt(sqr(x) + 1)); //! inverse hyperbolic sine +function argcosh(x) = ln(x + sqrt(sqr(x) - 1)); //! inverse hyperbolic cosine +function argtanh(x) = ln((1 + x) / (1 - x)) / 2;//! inverse hyperbolic tangent +function argcoth(x) = ln((x + 1) / (x - 1)) / 2;//! inverse hyperbolic cotangent 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