We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Learn more about funding links in repositories.
Report abuse
There was an error while loading. Please reload this page.
1 parent 03a4251 commit 1e327e3Copy full SHA for 1e327e3
conversions/rec_to_pol.py
@@ -0,0 +1,33 @@
1
+import doctest
2
+import math
3
+
4
5
+def rec_to_pol(real: float, img: float) -> tuple:
6
+ """
7
+ https://en.wikipedia.org/wiki/Polar_coordinate_system
8
9
+ >>> rec_to_pol(5,-5)
10
+ (7.07, -45.0)
11
+ >>> rec_to_pol(-1,1)
12
+ (1.41, 135.0)
13
+ >>> rec_to_pol(-1,-1)
14
+ (1.41, -135.0)
15
+ >>> rec_to_pol(1e-10,1e-10)
16
+ (0.0, 45.0)
17
+ >>> rec_to_pol(-1e-10,1e-10)
18
+ (0.0, 135.0)
19
+ >>> rec_to_pol(9.75,5.93)
20
+ (11.41, 31.31)
21
+ >>> rec_to_pol(10000,99999)
22
+ (100497.76, 84.29)
23
24
25
26
+ mod = round(math.sqrt((real**2) + (img**2)), 2)
27
28
+ ang = round(math.degrees(math.atan2(img, real)), 2)
29
+ return (mod, ang)
30
31
32
+if __name__ == "__main__":
33
+ doctest.testmod()
0 commit comments