From 3cad4f27affa61351128efadc02d637ad0d8d4a6 Mon Sep 17 00:00:00 2001 From: Florian Festi Date: Sat, 18 Feb 2017 18:53:01 +0100 Subject: [PATCH] Add tangent() function --- boxes/vectors.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/boxes/vectors.py b/boxes/vectors.py index 4ec98ce..6381d42 100644 --- a/boxes/vectors.py +++ b/boxes/vectors.py @@ -62,6 +62,15 @@ def dotproduct(v1, v2): def circlepoint(r, a): return (r * math.cos(a), r * math.sin(a)) +def tangent(x, y, r): + "angle and length of a tangent to a circle at x,y with raduis r" + l1 = vlength((x, y)) + a1 = math.atan2(y, x) + a2 = math.asin(r / l1) + l2 = math.cos(a2) * l1 + + return (a1+a2, l2) + def rotm(angle): "Rotation matrix" return [[math.cos(angle), -math.sin(angle), 0],