在正交基础上将 3D 三角形转换为 2D

Converting 3D triangle to 2D in orthonormal basis

我有一个函数可以进行这种转换。但我不确定它是怎么做的。谁能解释一下并验证它是否正确?

/**
     * \brief Computes the coordinates of the vertices of a triangle
     * in a local 2D orthonormal basis of the triangle's plane.
     * \param[in] p0 , p1 , p2 the 3D coordinates of the vertices of 
     *   the triangle
     * \param[out] z0 , z1 , z2 the 2D coordinates of the vertices of
     *   the triangle
     */
    static void project_triangle(
        const vec3& p0, 
        const vec3& p1, 
        const vec3& p2,
        vec2& z0,
        vec2& z1,
        vec2& z2
    ) {
        vec3 X = p1 - p0;
        X.normalize(); // normalized by dividing x,y,z with length of the vector
        vec3 Z = cross(X,(p2 - p0));
        Z.normalize();
        vec3 Y = cross(Z,X);  //cross product
        const vec3& O = p0;

        double x0 = 0;
        double y0 = 0;
        double x1 = (p1 - O).length();
        double y1 = 0;
        double x2 = dot((p2 - O),X);
        double y2 = dot((p2 - O),Y);        

        z0 = vec2(x0,y0);
        z1 = vec2(x1,y1);
        z2 = vec2(x2,y2);        
    }

向量X,Y,Z构成正交基,其中X与p0-p1重合,Y在三角形平面内,Z垂直于该平面。

然后p0映射到二维平面的坐标原点,p1映射到OX轴,然后通过p0-p2向量在X和Y基向量上的投影计算p2坐标。