def __init__(self, arg):
if isinstance(arg, numbers.Real):
# We precompute sin and cos for rotations
self.angle = arg
self.cos = math.cos(self.angle)
self.sin = math.sin(self.angle)
elif isinstance(arg, Point):
# Point angle is the trigonometric angle of the vector
# [origin, Point]
pt = arg
try:
self.cos = pt.x / pt.length()
self.sin = pt.y / pt.length()
except ZeroDivisionError:
self.cos = 1
self.sin = 0
self.angle = math.acos(self.cos)
if self.sin < 0:
self.angle = -self.angle
else:
raise TypeError("Angle is defined by a number or a Point")
评论列表
文章目录