cart2bary {geometry}R Documentation

Conversion of Cartesian to Barycentric coordinates.

Description

Given the Cartesian coordinates of one or more points, compute the barycentric coordinates of these points with respect to a simplex.

Usage

cart2bary(X, P)

Arguments

X

Reference simplex in NN dimensions represented by a N+1N+1-by-NN matrix

P

MM-by-NN matrix in which each row is the Cartesian coordinates of a point.

Details

Given a reference simplex in NN dimensions represented by a N+1N+1-by-NN matrix an arbitrary point PP in Cartesian coordinates, represented by a 1-by-NN row vector, can be written as

P=βXP = \beta X

where β\beta is an N+1N+1 vector of the barycentric coordinates. A criterion on β\beta is that

iβi=1\sum_i\beta_i = 1

Now partition the simplex into its first NN rows XNX_N and its N+1N+1th row XN+1X_{N+1}. Partition the barycentric coordinates into the first NN columns βN\beta_N and the N+1N+1th column βN+1\beta_{N+1}. This allows us to write

PN+1XN+1=βNXN+βN+1XN+1XN+1P_{N+1} - X_{N+1} = \beta_N X_N + \beta_{N+1} X_{N+1} - X_{N+1}

which can be written

PN+1XN+1=βN(XN1NXN+1)P_{N+1} - X_{N+1} = \beta_N(X_N - 1_N X_{N+1})

where 1N1_N is an NN-by-1 matrix of ones. We can then solve for βN\beta_N:

βN=(PN+1XN+1)(XN1NXN+1)1\beta_N = (P_{N+1} - X_{N+1})(X_N - 1_N X_{N+1})^{-1}

and compute

βN+1=1i=1Nβi\beta_{N+1} = 1 - \sum_{i=1}^N\beta_i

This can be generalised for multiple values of PP, one per row.

Value

MM-by-N+1N+1 matrix in which each row is the barycentric coordinates of corresponding row of P. If the simplex is degenerate a warning is issued and the function returns NULL.

Note

Based on the Octave function by David Bateman.

Author(s)

David Sterratt

See Also

bary2cart

Examples

## Define simplex in 2D (i.e. a triangle)
X <- rbind(c(0, 0),
           c(0, 1),
           c(1, 0))
## Cartesian coordinates of points
P <- rbind(c(0.5, 0.5),
           c(0.1, 0.8))
## Plot triangle and points
trimesh(rbind(1:3), X)
text(X[,1], X[,2], 1:3) # Label vertices
points(P)
cart2bary(X, P)

[Package geometry version 0.4.7 Index]