<p>If you have a point $C$ on a line defined by a point $A$ and a point $B$, here is how you calculate the barycentric coordinates $(t_0,t_1)$:</p>

<p>$t_0 = \frac{sqrt((C_x-A_x)^2+(C_y-A_y)^2)}{sqrt((B_x-A_x)^2+(B_y-A_y)^2)}$</p>

<p>$t_1 = 1.0 - t_0$</p>

<p>In other words, you calculate the length of the vector from $A$ to $C$, and divide that by the length of the vector from $A$ to $B$.  This gives you $t_0$, and you can subtract that from 1.0 to get $t_1$ since barycentric coordinates always add up to 1.0.</p>

<p>A more mathish style version of the above is this:</p>

<p>$t_0 = \frac{\left\| C-A\right\|}{\left\| B-A\right\|}$</p>

<p>$t_1 = 1.0 - t_0$</p>

<p>But it's important to note that $C$ must be on the line defined by $A$ and $B$.  If that isn't the case, let us know and let us know what it is you are trying to do specifically.  For instance, maybe you want to project some other point $D$ onto the line $\overline{AB}$ and then find the barycentric coordinates of that projected point?</p>

CC BY-SA 3.0
2017-01-30T19:56:54.660Z
2017-01-30T19:56:54.660Z
Alan Wolfe
<p>Given a point and a line segment, how do you calculate the barycentric coordinates of the point to the line?</p>

<p>bool BarycentricCoordinates(const Vector3&amp; point, const Vector3&amp; a, const Vector3&amp; b, float&amp; u, float&amp; v, float epsilon)</p>

CC BY-SA 3.0
2017-01-29T00:04:15.003Z
Needs more clarification. Are `a` and `b` intended to be points defining the line? How are the barycentric coordinates defined relative to those points? Is `point` assumed to be _on_ the line, or might it be somewhere off the line? What is the intended role of `epsilon`?
Nathan Reed
CC BY-SA 3.0
2017-01-29T00:25:58.703Z
yes, a and b are intended to be points defining the line. yes, How are the barycentric coordinates defined relative to those points? point can be on or somewhere off the line. epsilon is the error range
MOJOMO
CC BY-SA 3.0
2017-01-29T17:08:25.487Z
Would you expect the barycentric coordinates of the point to be the same if the point is projected to the line?
PeteUK
CC BY-SA 3.0
2017-01-29T20:12:19.987Z
yes, barycentric coordinates of the point should be the same if the point is projected to the line
MOJOMO
CC BY-SA 3.0
2017-01-29T21:26:36.653Z
Baryenctric coordinates are used for shapes likes triangles or more complex shapes. Not sure how you can define them with respect to a line? Doesn't make a lot of sense to me? It would be good if you could edit your question and explain in more details what you are looking for (what's the problem at hand)
user18490
CC BY-SA 3.0
2017-01-30T19:40:55.330Z
Barycentric coordinates apply to all SIMPLICES (plural of simplex).  A line is a 1 dimensional simplex.
Alan Wolfe
<texture>
Barycentric Coordinates of a Point on a Line
MOJOMO
# Barycentric Coordinates of a Point on a Line

(Asked by: username_0 on 2017-01-28)

Given a point and a line segment, how do you calculate the barycentric coordinates of the point to the line?

bool BarycentricCoordinates(const Vector3& point, const Vector3& a, const Vector3& b, float& u, float& v, float epsilon)

**Tags:** texture

> **Comments:**
> **username_1**: Needs more clarification. Are `a` and `b` intended to be points defining the line? How are the barycentric coordinates defined relative to those points? Is `point` assumed to be _on_ the line, or might it be somewhere off the line? What is the intended role of `epsilon`?  
> **username_0**: yes, a and b are intended to be points defining the line. yes, How are the barycentric coordinates defined relative to those points? point can be on or somewhere off the line. epsilon is the error range  
> **username_2**: Would you expect the barycentric coordinates of the point to be the same if the point is projected to the line?  
> **username_0**: yes, barycentric coordinates of the point should be the same if the point is projected to the line  
> **username_3**: Baryenctric coordinates are used for shapes likes triangles or more complex shapes. Not sure how you can define them with respect to a line? Doesn't make a lot of sense to me? It would be good if you could edit your question and explain in more details what you are looking for (what's the problem at hand)  
> **username_4**: Barycentric coordinates apply to all SIMPLICES (plural of simplex).  A line is a 1 dimensional simplex.  

---

## 1 answers

### Answer by username_4 on 2017-01-30. Score: 2

If you have a point $C$ on a line defined by a point $A$ and a point $B$, here is how you calculate the barycentric coordinates $(t\_0,t\_1)$:

$t\_0 = \frac{sqrt((C\_x-A\_x)^2+(C\_y-A\_y)^2)}{sqrt((B\_x-A\_x)^2+(B\_y-A\_y)^2)}$

$t\_1 = 1.0 - t\_0$

In other words, you calculate the length of the vector from $A$ to $C$, and divide that by the length of the vector from $A$ to $B$. This gives you $t\_0$, and you can subtract that from 1.0 to get $t\_1$ since barycentric coordinates always add up to 1.0.

A more mathish style version of the above is this:

$t\_0 = \frac{\left\| C-A\right\|}{\left\| B-A\right\|}$

$t\_1 = 1.0 - t\_0$

But it's important to note that $C$ must be on the line defined by $A$ and $B$. If that isn't the case, let us know and let us know what it is you are trying to do specifically. For instance, maybe you want to project some other point $D$ onto the line $\overline{AB}$ and then find the barycentric coordinates of that projected point?


---

