From barycentric to cartesian

I have the following function for converting a point in the same plane as a triangle to a barycentric point.

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

How can I write an inverse of this operation? I would like to write a function that takes a barycentric coordinate and returns a Cartesian point.

+6
source share
1 answer

The Cartesian coordinates of a point can be calculated as a linear combination with barycentric coordinates as coefficients:

 Vector3d Tri::cartesian(const Vector3d& barycentric) const { return barycentric.x * p0 + barycentric.y * p1 + barycentric.z * p2; } 
+8
source

Source: https://habr.com/ru/post/919325/


All Articles