在 THREE.js 中,如何缩放原始数据集,以便显示的所有点都包含在给定宽度和高度的平面的尺寸范围内?

In THREE.js, how can I scale a raw data set so that all points displayed are contained within the dimensions of a plane of given width and height?

我使用平面对象作为包含我的数据的 THREE.Points 对象的笛卡尔平面。用于转换原始集的矢量函数必须能够缩放任何数据集,以便显示的点始终适合平面的边界。这是我目前所拥有的:

for(var k=0; k<data.length; k++) {

    points.geometry.vertices.push(

        new THREE.Vector3( //function for the x-coordinate,
                           //function for the y-coordinate,
                           0 )
    );
}

我自己找到了这个问题的答案。这是代码:

for(var k=0; k<data.length; k++) {

    points.geometry.vertices.push(

        new THREE.Vector3( 

            width*((k-(data.length/2))/data.length), //x

            height*(data[k]/(2*range)), //y

            0 //z
        )
    );
}