dasbob/case/functions.scad
2024-12-06 13:39:38 +01:00

15 lines
569 B
OpenSCAD

function to_cardinal_2d(a, d) = [
d * sin(a),
d * cos(a)
];
function move_polar_2d(p, angle, dist) = to_cardinal_2d(angle, dist) + p;
function line_len_2d(p) = sqrt(p[0]*p[0] + p[1]*p[1]);
function line_len_3d(p) = sqrt(p[0]*p[0] + p[1]*p[1] + p[2]*p[2]);
function angle_2d(p) = atan2(p[0], p[1]);
function _tangent_single_angle_2d(to, r, other_side) = angle_2d(to) + ((other_side) ? -1 : 1)*acos(r / line_len_2d(to));
function tangent_single_2d(to, r, center, other_side=false) =
move_polar_2d(center, _tangent_single_angle_2d(to - center, r, other_side), r);