Skip to contents

This function constructs the coordinates of vertices of a regular simplex in \(\mathbb{R}^{\code{dim}}\) and returns the first n of them,

  • scaled so that the pairwise Euclidean distance between any two vertices equals dist,

  • and centered so their centroid is at center.

Usage

equidistant_vectors(dim, n = dim + 1, dist = 1, center = rep(0, dim))

Arguments

dim

[integer(1)]
The dimension.

n

[integer(1)]
The number of vertices to return. Cannot be larger than dim + 1.

dist

[numeric(1)]
Desired pairwise Euclidean distance between any two vertices.

center

[numeric(dim)]
Desired center.

Value

A matrix, where each column is a vertex of the simplex.

Examples

dim <- n <- 3
(dist <- runif(1))
#> [1] 0.1585943
(center <- rnorm(dim))
#> [1]  0.795886 -1.094739  1.073491
(V <- equidistant_vectors(dim = dim, n = n, dist = dist, center = center))
#>            [,1]      [,2]      [,3]
#> [1,]  0.8822138  0.752722  0.752722
#> [2,] -1.1100001 -1.018436 -1.155782
#> [3,]  1.0470585  1.047058  1.126356
rowMeans(V)
#> [1]  0.795886 -1.094739  1.073491
dist(t(V))
#>           1         2
#> 2 0.1585943          
#> 3 0.1585943 0.1585943