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 |
P |
|
Details
Given a reference simplex in dimensions represented by a
-by-
matrix an arbitrary point
in
Cartesian coordinates, represented by a 1-by-
row vector, can be
written as
where is an
vector of the barycentric coordinates.
A criterion on
is that
Now partition the simplex into its first rows
and
its
th row
. Partition the barycentric
coordinates into the first
columns
and the
th column
. This allows us to write
which can be written
where is an
-by-1 matrix of ones. We can then solve
for
:
and compute
This can be generalised for multiple values of
, one per row.
Value
-by-
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 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)