基于向量的定向平面

时间:2016-01-03 19:30:03

标签: javascript math graphics three.js linear-algebra

我想画一个有一个点阵列的飞机(包括原点)。 three.js库在原点上绘制平面,面向xy平面。现在,我无法将它从原点移动到一个包含点的位置。

到目前为止,我已经设法找到一种方法来定位位于y轴上的一些平面:

    var directionalVectors  = __getDirectionVectors(points);
    var normal = __getNormalOfPlane(directionalVectors);  
    var angleXY = __getAngleBetweenPlanes( normal, new THREE.Vector3(0, 0, 1) );
    plane.rotateY(- angleXY );
    plane.translateY( planeDimensions.width /2.0);
    plane.translateX( planeDimensions.height /2.0);

这就是我计算方向向量的方法:

var __getDirectionVectors = function( points ){
    var numOfPoints = points.length, i;
    var pointOne, pointTwo, directionalVectors = [], directionalVector;

    for( i = 0; i < numOfPoints - 1; i++){
        pointOne = points[i];
        pointTwo = points[i + 1];
        directionalVector = new THREE.Vector3().subVectors(pointOne, pointTwo);
        directionalVectors.push(directionalVector);
    }

    return directionalVectors;
};

这是我计算法线的方法:

    var __getNormalOfPlane = function(vectors){
    var numOfVectors = vectors.length;
    var vectorOne, vectorTwo, normal;

    if( numOfVectors >= 2){
        vectorOne = vectors[0];
        vectorTwo = vectors[1];
        normal = new THREE.Vector3().crossVectors(vectorOne, vectorTwo);
    }
    return normal;
};

这就是我计算平面和XY平面之间角度的方法:

    //http://www.netcomuk.co.uk/~jenolive/vect14.html
    var __getAngleBetweenPlanes = function( normalOne, normalTwo){

        var dotPdt = normalOne.dot(normalTwo);
        var angle = Math.acos(  dotPdt / ( normalOne.length() * normalTwo.length() ) );
        return angle;
    }

有什么方法可以为所有类型的飞机正确定位飞机?

0 个答案:

没有答案