using System; using DoublePair = System.Tuple; namespace BizHawk.Client.Common { public static class PolarRectConversion { /// angle in degrees /// rectangular (Cartesian) coordinates (x, y) public static DoublePair PolarDegToRect(double r, double θ) => PolarRadToRect(r, θ * Math.PI / 180); /// angle in radians /// rectangular (Cartesian) coordinates (x, y) public static DoublePair PolarRadToRect(double r, double θ) => new DoublePair(r * Math.Cos(θ), r * Math.Sin(θ)); /// polar coordinates (r, θ) where θ is in degrees public static DoublePair RectToPolarDeg(double x, double y) => new DoublePair(Math.Sqrt(x * x + y * y), Math.Atan2(y, x) * 180 / Math.PI); } }