Barycentric Coordinates For Triangle
Barycentric Coordinates For Triangle
X
2. Translation: Simply subtract xhit from each of the
xhit
projected 2D vertices.
4. Count the crossings with the positive x axis. Think about how to organize
this counting to do the minimum number of calculations. Note: you do not
necessarily have to calculate where the positive x axis crosses an edge. You
only need to know whether or not it crosses the edge.
For example:
• if x = p0 , u = 1, v = 0, w = 0,
• if x = p1 , u = 0, v = 1, w = 0,
• if x = p2 , u = 0, v = 0, w = 1,
• if x is on the p1 , p2 edge, u = 0,
• if x is on the p2 , p0 edge, v = 0,
• if x is on the p0 , p1 edge, w = 0.
The areas can be found by the trigonometric rela-
tion:
A = 1/2ab sin θ,
b h
where a and b are two sides of a triangle and θ is
the angle between them. Note that sin θ = h/b, so a
h = b sin θ. Therefore, A = 1/2ah = 1/2ab sin θ. We
know that the magnitude of the cross product ka × bk = kakkbk sin θ, so we
can use cross product to determine areas.
We can do even better if we note that
a×b
b = n,
ka × bk
n
a where n is the normal to the plane defined by a, b and
a common vertex.
Now, referring to the diagram to the right, let
p2
e01 = p1 − p0 ,
e20
e12 = p2 − p1 , n e12
e20 = p0 − p2 , Av x Au
Aw
n = (e01 × e12 )/ke01 × e12 k.
p0 e01 p1
Barycentric Coordinates
9.3. A SPECIAL CASE: RAY-TRIANGLE INTERSECTION 61
We see that
1
A= (e01 × e12 ) · n,
2
1
Au = [e12 × (x − p1 )] · n,
2
1
Av = [e02 × (x − p2 )] · n.
2
This gives us
u = Au /A, v = Av /A, w = 1 − u − v.
Note that computation with dot product instead of absolute value gives us a
signed area. This means that if x is outside of a triangle, at least one of the
u, v, w coordinates will be negative, as demonstrated in the following figures.
p2
x
n e12
x
p2
e12
x = p2 + u(p0 − p2 ) + v(p1 − p2 ).
Another way to see this is that u, v and w weight vertices to give the position
of x. By rearranging the equation above, we have