如何使用 4 个角的位置获取 3d 平面的角度

How to get the angle of a 3d plane using the position of the 4 corners

大约 6 个月前,我开始制作 3d 图形引擎。 它看起来已经很好了。我已经实现了旋转、平移、缩放、Z 缓冲区(画家的算法)...我现在正在研究镜面反射着色器。为此,我需要一些方法来获取他个人面孔的角度 我的问题是,如何通过只知道四个角的位置来获得平面的角度?

这是我目前得到的:

function faceAngle(verts,faces){
    var arr = [];
    for(var i=0;i<faces.length;i++){
    var posA = verts[faces[i][0]];//the four corners
    var posB = verts[faces[i][1]];//    A       B
    var posC = verts[faces[i][2]];//      -----
    var posD = verts[faces[i][3]];//     |     |
                                  //     |     |
    var ar = [];                  //      -----
    ar.push(/*some Maths*/);//x   //    D       C
    ar.push(/*some Maths*/);//y
    ar.push(/*some Maths*/);//z
    arr.push(ar);
    }
    return arr;
}

space 中的平面方向由法向量定义。要得到这个向量,计算cross product of two edges(属于平面)。所以你只需要平面上的三个非共线点。

n = (posB - posA) x (posC - posA)   //cross product of two vectors

请注意,归一化(单位)法向量的分量为 direction cosines