【发布时间】:2017-09-21 13:38:31
【问题描述】:
我有一个函数可以进行这种转换。但我不确定它的表现如何。谁能解释一下并验证它是否正确?
/**
* \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);
}
【问题讨论】:
-
你知道多少3D几何和矢量代数?例如,您了解标准化、叉积和点积吗?
标签: math geometry projection normalize