/// <summary> /// 直角坐标转球面坐标 /// </summary> /// <param name="coord"></param> /// <returns></returns> public static SphericalCoordinatePoint ToSphericalCoordinatePoint(RectangularCoordinatePoint coord) { double radius = GetModuloFromCartesianCoord(coord); double theta = GetThetaFromCartesianCoord(coord); double phi = GetPhiFromCartesianCoord(coord); return new SphericalCoordinatePoint(radius, theta, phi); }
private static double GetThetaFromCartesianCoord(RectangularCoordinatePoint coord) { return Math.Acos(coord.Z / GetModuloFromCartesianCoord(coord)); }
private static double GetPhiFromCartesianCoord(RectangularCoordinatePoint coord) { return Math.Atan(coord.Y / coord.X); }
private static double GetModuloFromCartesianCoord(RectangularCoordinatePoint coord) { return Math.Sqrt(coord.X * coord.X + coord.Y * coord.Y + coord.Z * coord.Z); }
/// <summary> /// 复制坐标值到目标点 /// </summary> /// <param name="target"></param> public void CopyTo(RectangularCoordinatePoint target) { target.X = this.X; target.Y = this.Y; target.Z = this.Z; }
/// <summary> /// 从源点复制坐标值 /// </summary> /// <param name="source"></param> public void CopyFrom(RectangularCoordinatePoint source) { this.X = source.X; this.Y = source.Y; this.Z = source.Z; }