geometry.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:sketch-components 作者: ibhubs 项目源码 文件源码
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")
评论列表


问题


面经


文章

微信
公众号

扫码关注公众号