From 7c1c2a609bbb1f37a3c679cb01a75e1514a2d2ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Tue, 26 Nov 2019 12:54:02 +0200 Subject: [PATCH] normalize angles --- Karto/assignment4/measure.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Karto/assignment4/measure.py b/Karto/assignment4/measure.py index 202c909..54fbb07 100755 --- a/Karto/assignment4/measure.py +++ b/Karto/assignment4/measure.py @@ -3,6 +3,13 @@ from collections import namedtuple from decimal import Decimal as Dec from math import sin, cos, pi +def normalize(ang): + while ang > 180: + ang -= 360 + while ang <= -180: + ang += 360 + return ang + def guess(inp): if isinstance(inp, str) and '-' in inp: deg, mm, ss = inp.split('-') @@ -107,7 +114,7 @@ if __name__ == '__main__': nxt = vertices[1 if i == len(vertices) - 1 else i+1] pts = "%d-%d" % (v.point, nxt.point) - draw = "@%.3f<%.4f" % (v.len, 90 - v.dirang) + draw = "@%.3f<%.4f" % (v.len, normalize(90 - v.dirang)) print("%5s: %19s acadcoords:(%.3f,%.3f)" % \ (pts, draw, v.coords.acadx, v.coords.acady))