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.8884956
(center <- rnorm(dim))
#> [1] -1.6545922 -1.5794826  0.7969991
(V <- equidistant_vectors(dim = dim, n = n, dist = dist, center = center))
#>            [,1]       [,2]      [,3]
#> [1,] -1.1709565 -1.8964101 -1.896410
#> [2,] -1.6649781 -1.1520049 -1.921465
#> [3,]  0.6489165  0.6489165  1.093164
rowMeans(V)
#> [1] -1.6545922 -1.5794826  0.7969991
dist(t(V))
#>           1         2
#> 2 0.8884956          
#> 3 0.8884956 0.8884956