我有以下函数可以将与三角形在同一平面上的点转换为重心点。
// p0, p1 and p2 and the points that make up this triangle
Vector3d Tri::barycentric(Vector3d p) {
double triArea = (p1 - p0).cross(p2 - p0).norm() * 0.5;
double u = ((p1 - p).cross(p2 - p).norm() * 0.5) / triArea;
double v = ((p0 - p).cross(p2 - p).norm() * 0.5) / triArea;
double w = ((p0 - p).cross(p1 - p).norm() * 0.5) / triArea;
return Vector3d(u,v,w);
}
如何写出这个操作的逆运算?我想编写一个采用重心坐标并返回笛卡尔点的函数。
最佳答案
点的笛卡尔坐标可以计算为以重心坐标为系数的线性组合:
Vector3d Tri::cartesian(const Vector3d& barycentric) const
{
return barycentric.x * p0 + barycentric.y * p1 + barycentric.z * p2;
}
关于c++ - 从重心到笛卡尔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11262391/