Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

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.

Details

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

P = β X

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

∑_iβ_i = 1

Now partition the simplex into its first N rows X_N and its N+1th row X_{N+1}. Partition the barycentric coordinates into the first N columns β_N and the N+1th column β_{N+1}. This allows us to write

P_{N+1} - X_{N+1} = β_N X_N + β_{N+1} X_{N+1} - X_{N+1}

which can be written

P_{N+1} - X_{N+1} = β_N(X_N - 1_N X_{N+1})

where 1_N is an N-by-1 matrix of ones. We can then solve for β_N:

β_N = (P_{N+1} - X_{N+1})(X_N - 1_N X_{N+1})^{-1}

and compute

β_{N+1} = 1 - ∑_{i=1}^Nβ_i

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

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.

Note

Based on the Octave function by David Bateman.

Author(s)

David Sterratt

See Also

Examples

## 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)

geometry

Mesh Generation and Surface Tessellation

v0.4.5
GPL (>= 3)
Authors
Jean-Romain Roussel [cph, ctb] (wrote tsearch function with QuadTrees), C. B. Barber [cph], Kai Habel [cph, aut], Raoul Grasman [cph, aut], Robert B. Gramacy [cph, aut], Pavlo Mozharovskyi [cph, aut], David C. Sterratt [cph, aut, cre] (<https://orcid.org/0000-0001-9092-9099>)
Initial release
2019-12-02

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.