Barycentric coordinates
From DmWiki
Barycentric coordinates were named by the german mathematican Franz Ferdinand Möbius, who is otherwise famous for inventing the Möbius Strip (http://en.wikipedia.org/wiki/M%C3%B6bius_strip).
Given a system described by the set of points P = [A, B, ..., N] and a set of barycentric coordinates [a, b, c, ..., n] the center of mass (barycenter) of P lies at the point p = aA + bB + ... + nN. In computer graphics, barycentric coordinates are commonly used to describe points on convex polygons, since p is defined to be insided the convex hull of P, if a + b + ... + n = 1.
Barycentric coordinates are used, for example, in computing ray-triangle intersections.
| Table of contents |
Computation for n-Simplexes
An n-dimensional simplex is defined as the convex hull formed by n + 1 affinely independent points. For instance, a 0-simplex is a point, a 1-simplex is a line, a 2-simplex is a triangle, a 3-simplex is a tetrahedron, etc. An n-simplex can exist in any dimension of n or higher. The most common example in computer graphics is a 2-simplex (triangle), which typically exists on a plane in 3D. Whether or not an n-simplex exists in n dimensions or higher determines which approach we should use to calculate the barycentric coordinates of a point.
If we have n + 1 affinely independent points, we can generate n linearly independent basis vectors by treating a single point as the "origin". Given the points
defining the simplex, we generate basis vectors
. These basis vectors define an n dimensional subspace. If we let r be the point we're testing, then we also treat it as though p0 is the origin by letting v = (r - p0). Our goal is to find the coordinates of v in this subspace, which are essentially the barycentric coordinates.
n-Simplex in n dimensions
Given n linearly independent vectors in n dimensions, we construct an nxn matrix
which has the basis vectors as the columns:
The point v can then be expressed in terms of the transformation
, where
is a vector containing the barycentric coordinates
for points p1 through pn. We can solve for
by multiplying both sides of the equation by
, such that
. We are assured the matrix is invertible because it's square and the columns are linearly independent. The barycentric coordinate for p0 is then just
. If
, then the point is within the simplex.
n-Simplex in more than n dimensions
As before, we construct a matrix
using the n linearly independent basis vectors as the columns. However, we won't be able to simply invert this matrix and solve for
because it is tall and hence un-invertible.
Starting from the equation
, we can rearrange the terms to get
. The dot product of any vector with the zero vector is zero, so the dot product of each basis vector with
should be 0. This gives us the equation
. We can now finally solve for
, which is
. It is also the case that the dot product of any vector with any other perpendicular vector is also zero. So the above process would work for any vector
that was perpendicular to all the basis vectors. This has the effect of projecting (http://en.wikipedia.org/wiki/Projection_(linear_algebra)) all vectors orthogonally onto the subspace.
Links
http://www.geometry.caltech.edu/pubs/WSHD05.pdf - Barycentric Coordinates for Complex Sets
http://www2.in.tu-clausthal.de/~hormann/papers/Floater.2006.AGC.pdf - A General Construction of Barycentric Coordinates over Convex Polygons
