打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
三维空间中直角坐标与球坐标的相互转换
package hans_gis.coord
{
    public class CoordsTransform
    {
        public function CoordsTransform()
        {
        }
         
        public function CartesianToSpherical(coord:CartesianCoord):SphericalCoord{
            var radius = this.GetModuloFromCartesianCoord(coord);
            var theta = this.GetThetaFromCartesianCoord(coord);
            var phi = this.GetPhiFromCartesianCoord(coord);
            return new SphericalCoord(radius, theta, phi);
        }
         
        protected function GetModuloFromCartesianCoord(coord:CartesianCoord):Number
        {
            return Math.sqrt( coord.x*coord.x + coord.y*coord.y + coord.z*coord.z );
        }
         
        protected function GetThetaFromCartesianCoord(coord:CartesianCoord):Number{
//          return Math.atan(Math.sqrt(coord.x*coord.x + coord.y*coord.y)/coord.z);
            return Math.acos(coord.z/this.GetModuloFromCartesianCoord(coord));
        }
         
        protected function GetPhiFromCartesianCoord(coord:CartesianCoord):Number{
            return Math.atan(coord.y/coord.x);
        }
         
        public function SphericalToCartesian(coord:SphericalCoord):CartesianCoord{
            var x = this.GetXFromSphericalCoord(coord);
            var y = this.GetYFromSphericalCoord(coord);
            var z = this.GetZFromSphericalCoord(coord);
            return new CartesianCoord(x, y, z);
        }
         
        protected function GetXFromSphericalCoord(coord:SphericalCoord):Number{
            return coord.radius*Math.sin(coord.theta)*Math.cos(coord.phi);
        }
         
        protected function GetYFromSphericalCoord(coord:SphericalCoord):Number{
            return coord.radius*Math.sin(coord.theta)*Math.sin(coord.phi);
        }
         
        protected function GetZFromSphericalCoord(coord:SphericalCoord):Number{
            return coord.radius*Math.cos(coord.theta);
        }
    }
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
TWaver版3D化学元素周期表
js特效 博客园
动态雪花飘落(冬天来了,春天还会远吗)
百度坐标坐标系之间的转换(JS版代码)
fourier series
[Flash] MC绕圆心拖动
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服