经纬度高度转ThreeJS的xyz坐标

// 计算位置
function calcPosition(lng, lat, alt) {
    var phi = (90-lat)*(Math.PI/180),
        theta = (lng+180)*(Math.PI/180),
        radius = alt+200,
        x = -(radius * Math.sin(phi) * Math.cos(theta)),
        z = (radius * Math.sin(phi) * Math.sin(theta)),
        y = (radius * Math.cos(phi));
    return {x: x, y: y, z: z};
}

调用

calcPosition(114.662688, 30.791616, 3459); // {x: -1311.5833759459222, y: 1873.1049219485822, z: -2856.4852527738162}

欢迎关注:http://fenxianglu.cn/

你可能感兴趣的:(前端,javascript)