Barycentric coordinates, line by line
A triangle has three corners A, B, C. Barycentric coordinates
describe any point as a weighted blend of those three corners.
Step 1 — write a point as a blend of the corners. Pick three weights
u, v, w and mix:
P = u\,A + v\,B + w\,C.
Step 2 — make the weights sum to one. To land on the triangle's
plane (not float off it), the weights must be a true average — they sum to one:
u + v + w = 1.
With this constraint, (u,v,w) = (1,0,0) is corner
A, (0,1,0) is B,
(0,0,1) is C, and
(\tfrac13,\tfrac13,\tfrac13) is the centroid. Each weight measures
"how much of that corner" is in the mix.
Step 3 — read off "inside" from the signs. A point sits inside the
triangle exactly when all three weights are non-negative. A negative weight means you've
stepped past the edge opposite that corner:
P \text{ is inside } \triangle ABC \iff u \ge 0,\ v \ge 0,\ w \ge 0 \quad (\text{with } u+v+w=1).
That single sign test is the whole containment check — no angle sums, no winding loops.
Step 4 — intersect by meeting the plane, then testing the weights. To hit
triangle ABC with a
ray,
first find where the ray crosses the triangle's plane (a single
t), then compute that point's barycentric weights and check they
are all \ge 0. Inside ⇒ a real hit; any negative weight ⇒ the ray
passed through the plane but outside the triangle.
Hitting the triangle's plane is not the same as hitting the triangle. A ray
can solve for t perfectly well and still land well outside the
triangle's boundary — planes are infinite, triangles aren't. The plane-hit only tells you
where the ray would land if the surface extended forever; it says nothing about
whether that point falls inside the three edges.
That's why the sign test in Step 3 is a separate, essential check, not an optional
nicety: all of u \ge 0, v \ge 0
and w \ge 0 must hold together. Getting
u + v + w = 1 right but forgetting to check the individual signs
is a classic bug — the arithmetic looks fine, but a single negative weight means the ray
actually missed, and treating it as a hit paints triangles far larger than they really are.
Step 5 — Möller–Trumbore does it in one shot. The famous Möller–Trumbore
algorithm fuses those two steps: using
cross
and dot products of the edge vectors e_1 = B - A,
e_2 = C - A and the ray, it solves directly for
(t, v, w) at once — recovering
u = 1 - v - w for free — and bails out the instant a weight goes
negative. It never explicitly builds the plane; the barycentrics fall straight out of the linear
system.
Step 6 — reuse the weights to interpolate. Here is the payoff. Each vertex
carries data — a normal, a colour, a texture coordinate. The same
u, v, w that proved the hit blend that data smoothly across the
face:
\text{value at } P = u\,(\text{value}_A) + v\,(\text{value}_B) + w\,(\text{value}_C).
The intersection test and the shading interpolation share one set of numbers. That is why
barycentrics are everywhere in graphics.
For a triangle A, B, C:
-
Barycentric form — any point is
P = uA + vB + wC with
u + v + w = 1.
-
Inside test —
P lies in the triangle iff
u, v, w \ge 0.
-
Möller–Trumbore — solve the ray against the triangle directly for
(t, v, w) with cross/dot products; reject the moment a weight is
negative.
-
Interpolation — the same u, v, w blend
per-vertex data (normals, colours, texture coordinates) smoothly across the face.
Barycentric interpolation is not a niche trick — it is how a rasteriser fills a
triangle. Assign each corner a colour and blend by u, v, w across
the interior and you have Gouraud shading: a single triangle washes
smoothly from red at A through green at B
to blue at C, every interior pixel a weighted mix of the three.
Swap "colour" for "texture coordinate (s, t)" and the same blend
becomes texture mapping: the weights tell each pixel which texel to fetch, so
an image stretches correctly over the face. Swap in "vertex normal" and you get the
smooth normals
that make a faceted mesh look round. The same three numbers, asked to carry whatever data the
vertices hold — the most reused little vector in real-time rendering.