- Home /

# For raycast hits, what is a "barycentric coordinate"?

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?

**Answer** by Bunny83
·
Jul 02, 2019 at 04:47 PM

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).

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.

### Follow this Question

### Related Questions

Raycast script help? 1 Answer

Can you figure out raycast origin position from RacyastHit? 2 Answers

Door script using Raycast 1 Answer

Raycast Not Drawing In Target Direction? 0 Answers

Help finding out which side of a cube a raycast hits 1 Answer