From ca5ee3d65b033e70b8307ed1d0ccb27430e4b317 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Yael=20Puente=20Ruiz?= <71954593+SaulPuente@users.noreply.github.com> Date: Mon, 10 Oct 2022 17:42:04 -0500 Subject: [PATCH] Coordinate systems conversion --- cartesian2polar.py | 14 ++++++++++++++ polar2cartesian.py | 13 +++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 cartesian2polar.py create mode 100644 polar2cartesian.py diff --git a/cartesian2polar.py b/cartesian2polar.py new file mode 100644 index 00000000..8b862be8 --- /dev/null +++ b/cartesian2polar.py @@ -0,0 +1,14 @@ +from math import acos, sqrt, pi + +# Read values for x and y +x = float(input("x = ")) +y = float(input("y = ")) + +# Convert polar coordinates to cartesian +r = sqrt(x**2 + y**2) +θ = acos(x/r) +θ *= 1 if y >= 0 else -1 + +# Print results +print("r = " + str(r)) +print("θ = " + str(θ)) diff --git a/polar2cartesian.py b/polar2cartesian.py new file mode 100644 index 00000000..d0ee58d4 --- /dev/null +++ b/polar2cartesian.py @@ -0,0 +1,13 @@ +from math import cos, sin + +# Read values for r and θ +r = float(input("r = ")) +θ = float(input("θ = ")) + +# Convert polar coordinates to cartesian +x = r*cos(θ) +y = r*sin(θ) + +# Print results +print("x = " + str(x)) +print("y = " + str(y))