/// <summary> /// Coordinate transformation, from spherical to cartesion. /// </summary> /// <param name="spherical">Sperical coordinate: R, Theta: 90°..-90°, Phi: 0°..360°; angles in radians.</param> /// <returns>Cartesian coordinate: X,Y,Z.</returns> public Coordinate_Cartesian CoordinateTransformation_SphericalToCartesion(Coordinate_Sperical spherical) { Coordinate_Cartesian cartesian = new Coordinate_Cartesian(); cartesian.X = spherical.R * Math.Cos(spherical.Theta) * Math.Cos(spherical.Phi); cartesian.Y = spherical.R * Math.Cos(spherical.Theta) * Math.Sin(spherical.Phi);; cartesian.Z = spherical.R * Math.Sin(spherical.Theta); return(cartesian); }
/// <summary> /// Coordinate transformation, from cartesion to spherical. /// </summary> /// <param name="cartesian">Cartesian coordinate: X,Y,Z.</param> /// <returns>Sperical coordinate: R, Theta: 90°..-90°, Phi: 0°..360°; angles in radians.</returns> public Coordinate_Sperical CoordinateTransformation_CartesionToSpherical(Coordinate_Cartesian cartesian) { Coordinate_Sperical spherical = new Coordinate_Sperical(); spherical.R = Math.Sqrt((cartesian.X * cartesian.X + cartesian.Y * cartesian.Y + cartesian.Z * cartesian.Z)); spherical.Theta = Math.Asin(cartesian.Z / spherical.R); spherical.Phi = Math.Atan2(cartesian.Y, cartesian.X); if (spherical.Phi < 0) { spherical.Phi = 2 * Math.PI + spherical.Phi; } return(spherical); }