Learn R Programming

geometry (version 0.3-5)

cart2bary: 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 $N$ dimensions represented by a $N+1$-by-$N$ matrix
P
$M$-by-$N$ matrix in which each row is the Cartesian coordinates of a point.

Value

  • $M$-by-$N+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.

Details

Given a reference simplex in $N$ dimensions represented by a $N+1$-by-$N$ matrix an arbitrary point $\mathbf{P}$ in Cartesian coordinates, represented by a 1-by-$N$ row vector, can be written as $$\mathbf{P} = \mathbf{\beta}\mathbf{X}$$ where $\mathbf{\beta}$ is a $N+1$ vector of the barycentric coordinates. A criterion on $\mathbf{\beta}$ is that $$\sum_i\beta_i = 1$$ Now partition the simplex into its first $N$ rows $\mathbf{X}_N$ and its $N+1$th row $\mathbf{X}_{N+1}$. Partition the barycentric coordinates into the first $N$ columns $\mathbf{\beta}_N$ and the $N+1$th column $\beta_{N+1}$. This allows us to write $$\mathbf{P - X}_{N+1} = \mathbf{\beta}_N\mathbf{X}_N + \mathbf{\beta}_{N+1}\mathbf{X}_{N+1} - \mathbf{X}_{N+1}$$ which can be written $$\mathbf{P - X}_{N+1} = \mathbf{\beta}_N(\mathbf{X}_N - \mathbf{1}\mathbf{X}_{N+1})$$ where $\mathbf{1}$ is a $N$-by-1 matrix of ones. We can then solve for $\mathbf{\beta}_N$: $$\mathbf{\beta}_N = (\mathbf{P - X}_{N+1})(\mathbf{X}_N - \mathbf{1}\mathbf{X}_{N+1})^{-1}$$ and compute $$\beta_{N+1} = 1 - \sum_{i=1}^N\beta_i$$ This can be generalised for multiple values of $\mathbf{P}$, one per row.

See Also

bary2cart

Examples

Run this code
## Define simplex in 2D (i.e. a triangle)
X <- rbind(c(0, 0),
           c(0, 1),
           c(1, 0))
## Cartesian cooridinates 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)

Run the code above in your browser using DataLab