user181351
user181351

Reputation:

From barycentric to cartesian

I have the following function to convert a point on the same plane as a triangle into 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 the inverse of this operation? I would like to write a function that takes a barycentric coord and returns the cartesian point.

Upvotes: 12

Views: 9508

Answers (1)

Viktor Latypov
Viktor Latypov

Reputation: 14467

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

Upvotes: 19

Related Questions