We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 03a4251 commit aa9baceCopy full SHA for aa9bace
conversions/polar_to_rectangular.py
@@ -0,0 +1,36 @@
1
+import math
2
+
3
4
+def pol_to_rec(mod: float, mag: float):
5
+ ### https://en.wikipedia.org/wiki/Polar_coordinate_system
6
+ """
7
+ >>> pol_to_rec(5, 53)
8
+ (3.01, 3.99)
9
+ >>> pol_to_rec(10, 0)
10
+ (10.0, 0.0)
11
+ >>> pol_to_rec(0, 45)
12
+ (0.0, 0.0)
13
+ >>> pol_to_rec(5, 90)
14
+ (0.0, 5.0)
15
+ >>> pol_to_rec(5, 180)
16
+ (-5.0, 0.0)
17
+ >>> pol_to_rec(5, 270)
18
+ (-0.0, -5.0)
19
+ >>> pol_to_rec(5, 360)
20
+ (5.0, -0.0)
21
22
23
+ rad = math.radians(mag)
24
25
+ real = round((mod * math.cos(rad)), 2)
26
+ img = round(mod * math.sin(rad), 2)
27
28
+ rec = (real, img)
29
30
+ return rec
31
32
33
+if __name__ == "__main__":
34
+ import doctest
35
36
+ doctest.testmod()
0 commit comments