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

时间:2017-09-21 13:38:32

标签: math geometry projection normalize

我有一个执行此转换的功能。但我不确定它是怎么做的。任何人都可以解释一下并验证它是否正确?

/**
     * \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);        
    }

1 个答案:

答案 0 :(得分:1)

矢量X,Y,Z形成标准正交基,其中X与p0-p1重合,Y位于三角形平面,Z垂直于该平面。

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