我一直在尝试将this amazing tutorial从Python翻译成Javascript。我没有使用Python的经验,但是我做了2D翻译工作,就是3D我遇到了麻烦。不知道如何正确翻译numpy.linspace函数和数字.sqrt将向量操作转换为javascript。到目前为止这是我得到的。提前多谢了
function buildSphere() {
var n = 246;
var sphereR = 300;
var theJSON = [];
for(i = 0; i < n; i++){
theJSON[i].coordinate = new mo.Point3D(0,0,0);
var goldenAng = Math.PI * (3 - Math.sqrt(5));
var theta = i * goldenAng;
var z = (1-1.0/n, 1.0/n-1, n);
var r = (Math.sqrt(1-i)*sphereR) * Math.sqrt(z);
theJSON[i].coordinate.x = r * Math.cos(theta);
theJSON[i].coordinate.y = r * Math.sin(theta);
theJSON[i].coordinate.z = z ;
}
}
我要翻译的Python代码如下:
n = 256
golden_angle = numpy.pi * (3 - numpy.sqrt(5))
theta = golden_angle * numpy.arange(n)
z = numpy.linspace(1 - 1.0 / n, 1.0 / n - 1, n)
radius = numpy.sqrt(1 - z * z)
points = numpy.zeros((n, 3))
points[:,0] = radius * numpy.cos(theta)
points[:,1] = radius * numpy.sin(theta)
points[:,2] = z
非常感谢您的光临,再次感谢!你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐