Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DIRECTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
* [Octal To Binary](conversions/octal_to_binary.py)
* [Octal To Decimal](conversions/octal_to_decimal.py)
* [Octal To Hexadecimal](conversions/octal_to_hexadecimal.py)
* [Polar To Rectangular](conversions/polar_to_rectangular.py)
* [Prefix Conversions](conversions/prefix_conversions.py)
* [Prefix Conversions String](conversions/prefix_conversions_string.py)
* [Pressure Conversions](conversions/pressure_conversions.py)
Expand Down
36 changes: 36 additions & 0 deletions conversions/polar_to_rectangular.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import math


def pol_to_rec(mod: float, mag: float):
### https://en.wikipedia.org/wiki/Polar_coordinate_system
"""
>>> pol_to_rec(5, 53)
(3.01, 3.99)
>>> pol_to_rec(10, 0)
(10.0, 0.0)
>>> pol_to_rec(0, 45)
(0.0, 0.0)
>>> pol_to_rec(5, 90)
(0.0, 5.0)
>>> pol_to_rec(5, 180)
(-5.0, 0.0)
>>> pol_to_rec(5, 270)
(-0.0, -5.0)
>>> pol_to_rec(5, 360)
(5.0, -0.0)
"""

rad = math.radians(mag)

real = round((mod * math.cos(rad)), 2)
img = round(mod * math.sin(rad), 2)

rec = (real, img)

return rec


if __name__ == "__main__":
import doctest

doctest.testmod()
Loading