using System; namespace Science.Mathematics.VectorCalculus { public class Coordinates { private double x, y, z, r, theta, zc, rho, thetas, phi; public double CartesianX { get { return x; } set { x = value; } } public double CartesianY { get { return y; } set { y = value; } } public double CartesianZ { get { return z; } set { z = value; } } public double CylindricalR { get { return r; } set { r = value; } } public double CylindricalTheta { get { return theta; } set { theta = value; } } public double CylindricalZ { get { return zc; } set { zc = value; } } public double SphericalRho { get { return rho; } set { rho = value; } } public double SphericalTheta { get { return thetas; } set { thetas = value; } } public double SphericalAngleFromZ { get { return phi; } set { phi = value; } } public void FromCartesianToCylindrical() { r = Math.Sqrt(x * x + y * y); theta = Math.Atan(y / x); zc = z; } public void FromCartesianToSpherical() { rho = Math.Sqrt(x * x + y * y + z * z); thetas = Math.Atan(y / x); phi = Math.Acos(z / rho); } public void FromCylindricalToCartesian() { x = r * Math.Cos(theta); y = r * Math.Sin(theta); z = zc; } public void FromCylindricalToSpherical() { FromCylindricalToCartesian(); FromCartesianToSpherical(); } public void FromSphericalToCartesian() { x = rho * Math.Sin(phi) * Math.Cos(thetas); y = rho * Math.Sin(phi) * Math.Sin(thetas); z = rho * Math.Cos(phi); } public void FromSphericalToCylindrical() { FromSphericalToCartesian(); FromCartesianToCylindrical(); } } }