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_t
(real: float, img: float)
| 2 | |
| 3 | |
| 4 | def rectangular_to_polar(real: float, img: float) -> tuple[float, float]: |
| 5 | """ |
| 6 | https://en.wikipedia.org/wiki/Polar_coordinate_system |
| 7 | |
| 8 | >>> rectangular_to_polar(5,-5) |
| 9 | (7.07, -45.0) |
| 10 | >>> rectangular_to_polar(-1,1) |
| 11 | (1.41, 135.0) |
| 12 | >>> rectangular_to_polar(-1,-1) |
| 13 | (1.41, -135.0) |
| 14 | >>> rectangular_to_polar(1e-10,1e-10) |
| 15 | (0.0, 45.0) |
| 16 | >>> rectangular_to_polar(-1e-10,1e-10) |
| 17 | (0.0, 135.0) |
| 18 | >>> rectangular_to_polar(9.75,5.93) |
| 19 | (11.41, 31.31) |
| 20 | >>> rectangular_to_polar(10000,99999) |
| 21 | (100497.76, 84.29) |
| 22 | """ |
| 23 | |
| 24 | mod = round(math.sqrt((real**2) + (img**2)), 2) |
| 25 | ang = round(math.degrees(math.atan2(img, real)), 2) |
| 26 | return (mod, ang) |
| 27 | |
| 28 | |
| 29 | if __name__ == "__main__": |
nothing calls this directly
no outgoing calls
no test coverage detected