File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -8,9 +8,11 @@ Changelog
88
99
1010 New feature: ShapeFilter.rejects_collision()
11+ New feature: Added Vec2d.polar_tuple
1112 Optimized Vec2d.angle and Vec2d.angle_degrees
1213 Improved vec2d documentation
1314
15+
1416 Extra thanks for aetle for a number of suggestions for improvements in this pymunk release
1517
1618
Original file line number Diff line number Diff line change @@ -564,6 +564,22 @@ def int_tuple(self) -> Tuple[int, int]:
564564 """
565565 return round (self .x ), round (self .y )
566566
567+ @property
568+ def polar_tuple (self ) -> Tuple [float , float ]:
569+ """Return this vector as polar coordinates (length, angle)
570+
571+ See Vec2d.from_polar() for the inverse.
572+
573+ >>> Vec2d(2, 0).polar_tuple
574+ (2.0, 0.0)
575+ >>> Vec2d(2, 0).rotated(0.5).polar_tuple
576+ (2.0, 0.5)
577+ >>> Vec2d.from_polar(2, 0.5).polar_tuple
578+ (2.0, 0.5)
579+
580+ """
581+ return self .length , self .angle
582+
567583 @staticmethod
568584 def zero () -> "Vec2d" :
569585 """A vector of zero length.
@@ -595,6 +611,8 @@ def ones() -> "Vec2d":
595611 def from_polar (length : float , angle : float ) -> "Vec2d" :
596612 """Create a new Vec2d from a length and an angle (in radians).
597613
614+ See Vec2d.polar_tuple for the inverse.
615+
598616 >>> Vec2d.from_polar(2, 0)
599617 Vec2d(2.0, 0.0)
600618 >>> Vec2d(2, 0).rotated(0.5) == Vec2d.from_polar(2, 0.5)
You can’t perform that action at this time.
0 commit comments