Convert cartesian ↔ polar coordinates

cartesian to polar
Convert cartesian, (x, y), to polar, (r; θ), coordinates:
(common origin) 

r = √x² + y²
θ = acos(x/r) or asin(y/r)

Example:
Convert (2.5, 4.8) to (r; θ)

r = √2.5² + 4.8² ≈ 5.41
θ = acos(2.5/5.41) = 1.09 rad or 62.49°
(5.4; 1.1 rad) or (5.4; 62.5°)

—————————————————————
polar to cartesian
Convert polar, (r; θ), to cartesian, (x, y), coordinates:
(common origin)

x = cos(θ) · r
y = sin(θ) · r

Example:
convert (5.4; 62.5°) to (x, y)

x = cos(62.5°) · 5.4 = 2.5
y = sin(62.5°) · 5.4 = 4.8
(2.5, 4.8)

No comments: