-
-
Notifications
You must be signed in to change notification settings - Fork 46.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Function conversion rectangular number to polar * #9943 : adding test to elelectronics/electric_conductivity.py * updating DIRECTORY.md * Apply suggestions from code review * updating DIRECTORY.md * Rename rec_to_pol.py to rectangular_to_polar.py * updating DIRECTORY.md * Update conversions/rectangular_to_polar.py * Update conversions/rectangular_to_polar.py --------- Co-authored-by: Julia <[email protected]> Co-authored-by: juliaaragao <[email protected]> Co-authored-by: Christian Clauss <[email protected]> Co-authored-by: cclauss <[email protected]>
- Loading branch information
1 parent
7fa9b4b
commit a2be5ad
Showing
3 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import math | ||
|
||
|
||
def rectangular_to_polar(real: float, img: float) -> tuple[float, float]: | ||
""" | ||
https://en.wikipedia.org/wiki/Polar_coordinate_system | ||
>>> rectangular_to_polar(5,-5) | ||
(7.07, -45.0) | ||
>>> rectangular_to_polar(-1,1) | ||
(1.41, 135.0) | ||
>>> rectangular_to_polar(-1,-1) | ||
(1.41, -135.0) | ||
>>> rectangular_to_polar(1e-10,1e-10) | ||
(0.0, 45.0) | ||
>>> rectangular_to_polar(-1e-10,1e-10) | ||
(0.0, 135.0) | ||
>>> rectangular_to_polar(9.75,5.93) | ||
(11.41, 31.31) | ||
>>> rectangular_to_polar(10000,99999) | ||
(100497.76, 84.29) | ||
""" | ||
|
||
mod = round(math.sqrt((real**2) + (img**2)), 2) | ||
ang = round(math.degrees(math.atan2(img, real)), 2) | ||
return (mod, ang) | ||
|
||
|
||
if __name__ == "__main__": | ||
import doctest | ||
|
||
doctest.testmod() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters