diff --git a/readme.md b/readme.md index 5af1bb9..483472c 100644 --- a/readme.md +++ b/readme.md @@ -5455,6 +5455,7 @@ Maths utilities for manipulating vectors and matrices. | ```argsinh(x)``` | inverse hyperbolic sine | | ```argtanh(x)``` | inverse hyperbolic tangent | | ```augment(m)``` | Augment a matrix by adding an identity matrix to the right | +| ```circle_intersect(c1, r1, c2, r2)``` | Calculate one point where two circles in the X-Z plane intersect, clockwise around c1 | | ```cosh(x)``` | hyperbolic cosine | | ```coth(x)``` | hyperbolic cotangent | | ```degrees(radians)``` | Convert degrees to radians | diff --git a/tests/png/maths.png b/tests/png/maths.png index 4243925..d2fd22f 100644 Binary files a/tests/png/maths.png and b/tests/png/maths.png differ diff --git a/utils/maths.scad b/utils/maths.scad index 0130d60..883e753 100644 --- a/utils/maths.scad +++ b/utils/maths.scad @@ -146,3 +146,10 @@ function invert(m) = let(n =len(m), m = solve(augment(m))) [ //! Invert a matrix each m[i][j] ] ]; + +function circle_intersect(c1, r1, c2, r2) = //! Calculate one point where two circles in the X-Z plane intersect, clockwise around c1 + let( + v = c1 - c2, // Line between centres + d = norm(v), // Distance between centres + a = atan2(v.z, v.x) - acos((sqr(d) + sqr(r2) - sqr(r1)) / (2 * d * r2)) // Cosine rule to find angle from c2 + ) c2 + r2 * [cos(a), 0, sin(a)]; // Point on second circle