Added circle_intersect() calculation to maths.scad.

This commit is contained in:
Chris Palmer 2020-10-04 22:01:08 +01:00
parent e39af154bb
commit 90e7f1a315
3 changed files with 8 additions and 0 deletions

View File

@ -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 |

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 31 KiB

View File

@ -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