I haven’t seen a good explanation for this yet. It’s defined elsewhere as the “center of mass” for a triangle, pyramid, or for any dimensional “simplex”.
So in Unity, is it just the very center point of the raycast hit triangle?
I haven’t seen a good explanation for this yet. It’s defined elsewhere as the “center of mass” for a triangle, pyramid, or for any dimensional “simplex”.
So in Unity, is it just the very center point of the raycast hit triangle?
No, it is the hit point described in the barycentric coordinate system. A value of (1,0,0) would be the first corner of the triangle. A value of (0,1,0) would be the second corner of the triangle and (0,0,1) the third. As you might know if you read the barycentric coordinate system wiki page the 3 components of a barycentric coordinate will always add up to 1.0. So a value of (0.33, 0.33, 0.33) would be the center of the triangle (not that the 0.33 is actually 1/3 so 0.3 recurring).
The great thing about barycentric coordinates is that you can use them to easily interpolate any vertex attribute at a given point. For example if you have the position of v0, v1 and v2 of the triangle that was hit, you can calculate the actual hitpoint inside the triangle be just doing
Vector3 p = bary.x*v0 + bary.y*v2 + bary.z*v3;
However this does also work for normals, colors or texture coordinate. That’s actually how Unity calculates all the other information you get in the RaycastHit struct. If you want to work with barycentric coordinates yourself, I created this helper struct (Barycentric).