0% found this document useful (0 votes)
64 views4 pages

Barycentric Coordinates For Triangle

The document discusses barycentric coordinates for triangles. Barycentric coordinates define a point's position relative to the vertices of a triangle. The coordinates (u, v, w) measure the point's distance from each edge as a fraction of the triangle's total area. If u, v, w are all positive and sum to 1, the point is inside the triangle. The coordinates can also be used to convert between 3D spatial positions and positions relative to the triangle. Calculating barycentric coordinates involves taking cross products of the triangle's edge vectors.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views4 pages

Barycentric Coordinates For Triangle

The document discusses barycentric coordinates for triangles. Barycentric coordinates define a point's position relative to the vertices of a triangle. The coordinates (u, v, w) measure the point's distance from each edge as a fraction of the triangle's total area. If u, v, w are all positive and sum to 1, the point is inside the triangle. The coordinates can also be used to convert between 3D spatial positions and positions relative to the triangle. Calculating barycentric coordinates involves taking cross products of the triangle's edge vectors.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

9.3.

A SPECIAL CASE: RAY-TRIANGLE INTERSECTION


Barycentric Coordinates for Triangles 59

X
2. Translation: Simply subtract xhit from each of the
xhit
projected 2D vertices.

3. Use the positive x axis for the ray. X

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.

9.3 A special case: ray-triangle intersection

Note that a triangle is always a polygon. Three ordered


vertices always lie in a single plane, no edges can cross,
and there can be no holes. For this reason, graphics sys- 2

tems use triangles, wherever possible, to represent polyg-


onal surfaces, especially when it comes time to render
them. All of the desirable properties of a triangle turn 0 1
out to be extremely important to writing an efficient and
correct rendering algorithm.

For many calculations over triangles, a metric representation called barycentric


coordinates is very convenient. Barycentric coordinates provide a measuring
system that positions a point relative to the edges of the triangle, with a very
simple scheme for converting from regular 3D spatial coordinates to barycentric
coordinates, and from barycentric to 3D spatial coordinates.
Barycentric
60 Coordinates
CHAPTER 9. RAYCASTING POLYGONAL MODELS

Baycentric coordinates define a position with re-


spect to the positions of the vertices of a triangle. p2
Considering the diagram to the right, the point x
is internal to the triangle p0 , p1 , p2 , whose area is
A = Au + Av + Aw . The barycentric coordinates of
Av x Au
x are named u, v and w, and are defined as follows:
Aw
u = Au /A, p0 p1
v = Av /A,
w = Aw /A = 1 − u − v.

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

p0 p1 Note that [e × (x − p )] · n < 0 so u < 0.


12 1

x
p2

e12

p0 e01 p1 Note that Au + Aw > A, so u + w > 1, thus v < 0.

So given triangle p0 , p1 , p2 , a compact way to calculate the barycentric coor-


dinates of 3D point x with respect to this triangle consists of the following
steps:
vn = (p2 − p1 ) × (p1 − p0 ),
A = kvn k,
n = vn /A
u = [(p2 − p1 ) × (x − p1 )] · n/A,
v = [(p0 − p2 ) × (x − p2 )] · n/A,
w = 1 − u − v.
Note: the A in the above equations is actually twice the area of the triangle,
but since it only is used in ratios with other areas, this scale factor is cancelled
out.

Now our inside/outside test is simply


u ≥ 0, v ≥ 0, u + v ≤ 1.
Barycentric
62 Coordinates
CHAPTER 9. RAYCASTING POLYGONAL MODELS

Given barycentic coordinates (u, v, w) and vertices p0 , p1 , p2 for a triangle, we


can convert back to 3D coordinates by

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

x = up0 + vp1 + (1 − u − v)p2 .

This follows directly if we see the u and v coordinates


as measuring distance from an edge to a parallel line
p2 passing through the opposite vertex as shown in the
diagram to the left. We see that u measures the
fraction of the full distance from edge p0 , p1 to a
1v parallel line through p2 . Defined this way, u is a
p0 per unit measure, so u = 0 on p0 , p1 , u = 1 on the
1u p1
parallel line. The v coordinate is similar, measur-
ing distance from the edge p1 , p2 , and w measures
distance from p2 , p0 .

You might also like