Example #1
0
        /// <summary>
        /// 球面坐标转换到笛卡尔右手空间直角坐标系
        /// </summary>
        /// <param name="sphere"></param>
        /// <returns></returns>
        public static XYZ SphereToXyz(SphereCoord sphere)
        {
            double r   = sphere.Radius;
            double lat = sphere.Lat;
            double lon = sphere.Lon;

            return(SphereToXyz(lon, lat, r, sphere.Unit));
        }
Example #2
0
        /// <summary>
        /// 笛卡尔右手空间直角坐标系 转换到 球面坐标
        /// </summary>
        /// <param name="xyz"></param>
        /// <param name="unit"></param>
        /// <returns></returns>
        public static SphereCoord XyzToSphere(XYZ xyz, AngleUnit unit = AngleUnit.Degree)
        {
            double      x      = xyz.X;
            double      y      = xyz.Y;
            double      z      = xyz.Z;
            SphereCoord sphere = XyzToSphere(x, y, z, unit);

            return(sphere);
        }
Example #3
0
        /// <summary>
        /// XYZ to Sphere Coordinate
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="z"></param>
        /// <returns></returns>
        public static SphereCoord XyzToSphere(double x, double y, double z, AngleUnit unit = AngleUnit.Degree)
        {
            double radius = Math.Sqrt(x * x + y * y + z * z);
            double lon    = Math.Atan2(y, x);
            double lat    = Math.Atan2(z, Math.Sqrt(x * x + y * y));

            lon = AngularConvert.RadTo(lon, unit);
            lat = AngularConvert.RadTo(lat, unit);

            SphereCoord sphere = new SphereCoord(lon, lat, radius);

            return(sphere);
        }