@@ -263,12 +263,12 @@ def __sub__(self, other):
263
263
def __neg__ (self ):
264
264
return Vec2D (- self [0 ], - self [1 ])
265
265
def __abs__ (self ):
266
- return ( self [ 0 ] ** 2 + self [ 1 ] ** 2 ) ** 0.5
266
+ return math . hypot ( * self )
267
267
def rotate (self , angle ):
268
268
"""rotate self counterclockwise by angle
269
269
"""
270
270
perp = Vec2D (- self [1 ], self [0 ])
271
- angle = angle * math .pi / 180.0
271
+ angle = math .radians ( angle )
272
272
c , s = math .cos (angle ), math .sin (angle )
273
273
return Vec2D (self [0 ]* c + perp [0 ]* s , self [1 ]* c + perp [1 ]* s )
274
274
def __getnewargs__ (self ):
@@ -1597,7 +1597,7 @@ def radians(self):
1597
1597
>>> turtle.heading()
1598
1598
1.5707963267948966
1599
1599
"""
1600
- self ._setDegreesPerAU (2 * math .pi )
1600
+ self ._setDegreesPerAU (math .tau )
1601
1601
1602
1602
def _go (self , distance ):
1603
1603
"""move turtle forward by specified distance"""
@@ -1888,7 +1888,7 @@ def towards(self, x, y=None):
1888
1888
elif isinstance (x , TNavigator ):
1889
1889
pos = x ._position
1890
1890
x , y = pos - self ._position
1891
- result = round (math .atan2 (y , x )* 180.0 / math . pi , 10 ) % 360.0
1891
+ result = round (math .degrees ( math . atan2 (y , x )) , 10 ) % 360.0
1892
1892
result /= self ._degreesPerAU
1893
1893
return (self ._angleOffset + self ._angleOrient * result ) % self ._fullcircle
1894
1894
@@ -1903,7 +1903,7 @@ def heading(self):
1903
1903
67.0
1904
1904
"""
1905
1905
x , y = self ._orient
1906
- result = round (math .atan2 (y , x )* 180.0 / math . pi , 10 ) % 360.0
1906
+ result = round (math .degrees ( math . atan2 (y , x )) , 10 ) % 360.0
1907
1907
result /= self ._degreesPerAU
1908
1908
return (self ._angleOffset + self ._angleOrient * result ) % self ._fullcircle
1909
1909
@@ -1976,7 +1976,7 @@ def circle(self, radius, extent = None, steps = None):
1976
1976
steps = 1 + int (min (11 + abs (radius )/ 6.0 , 59.0 )* frac )
1977
1977
w = 1.0 * extent / steps
1978
1978
w2 = 0.5 * w
1979
- l = 2.0 * radius * math .sin (w2 * math .pi / 180.0 * self ._degreesPerAU )
1979
+ l = 2.0 * radius * math .sin (math .radians ( w2 ) * self ._degreesPerAU )
1980
1980
if radius < 0 :
1981
1981
l , w , w2 = - l , - w , - w2
1982
1982
tr = self ._tracer ()
@@ -2861,7 +2861,7 @@ def settiltangle(self, angle):
2861
2861
>>> turtle.fd(50)
2862
2862
"""
2863
2863
tilt = - angle * self ._degreesPerAU * self ._angleOrient
2864
- tilt = ( tilt * math .pi / 180.0 ) % ( 2 * math .pi )
2864
+ tilt = math .radians ( tilt ) % math .tau
2865
2865
self .pen (resizemode = "user" , tilt = tilt )
2866
2866
2867
2867
def tiltangle (self , angle = None ):
@@ -2885,7 +2885,7 @@ def tiltangle(self, angle=None):
2885
2885
>>> turtle.tiltangle()
2886
2886
"""
2887
2887
if angle is None :
2888
- tilt = - self . _tilt * ( 180.0 / math . pi ) * self ._angleOrient
2888
+ tilt = - math . degrees ( self . _tilt ) * self ._angleOrient
2889
2889
return (tilt / self ._degreesPerAU ) % self ._fullcircle
2890
2890
else :
2891
2891
self .settiltangle (angle )
@@ -2939,7 +2939,7 @@ def shapetransform(self, t11=None, t12=None, t21=None, t22=None):
2939
2939
if t11 * t22 - t12 * t21 == 0 :
2940
2940
raise TurtleGraphicsError ("Bad shape transform matrix: must not be singular" )
2941
2941
self ._shapetrafo = (m11 , m12 , m21 , m22 )
2942
- alfa = math .atan2 (- m21 , m11 ) % ( 2 * math .pi )
2942
+ alfa = math .atan2 (- m21 , m11 ) % math .tau
2943
2943
sa , ca = math .sin (alfa ), math .cos (alfa )
2944
2944
a11 , a12 , a21 , a22 = (ca * m11 - sa * m21 , ca * m12 - sa * m22 ,
2945
2945
sa * m11 + ca * m21 , sa * m12 + ca * m22 )
0 commit comments