View source: R/transformSimplex.R
simplex.createTransform | R Documentation |
This function generates a matrix to transform points in an (n-1) dimensional homogeneous coordinate representation of the (n-1) simplex to n-dimensional Cartesian coordinates.
The inverse transform can also be generated, and conversion can be to homogeneous coordinates instead of Cartesion ones.
simplex.createTransform(n, inverse=FALSE, keepHomogeneous=inverse)
n |
Dimension of the space |
inverse |
TRUE to convert from n-space coordinates to (n-1)-simplex coordinates |
keepHomogeneous |
TRUE to convert to homogeneous coordinates rather than Cartesian |
Multiply a coordinate vector in homogeneous coordinates by pre-multiplying by the generated matrix (see examples).
A transformation matrix.
Gert van Valkenhoef
simplex.createConstraints
har
E <- 1E-12 # Allowed numerical error # The origin in (n-1)-dimensional space should be the centroid of the simplex # when transformed to n-dimensional space transform <- simplex.createTransform(3) x <- transform %*% c(0, 0, 1) x stopifnot(abs(x - c(1/3, 1/3, 1/3)) < E) # The same should hold for the inverse transformation invTransform <- simplex.createTransform(3, inverse=TRUE) y <- invTransform %*% c(1/3, 1/3, 1/3, 1) y stopifnot(abs(y - c(0, 0, 1)) < E) # Of course, an arbitrary weight vector should transform back to itself transform <- simplex.createTransform(3, keepHomogeneous=TRUE) x <- c(0.2, 0.5, 0.3, 1.0) y <- transform %*% invTransform %*% x y stopifnot(abs(y - x) < E) # And we can apply the tranform to a matrix: a <- cbind(x, x, x) b <- transform %*% invTransform %*% a b stopifnot(abs(b - a) < E)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.