# Generating vertices of a simplex

**URL:** https://discourse.julialang.org/t/generating-vertices-of-a-simplex/61495
**Category:** Visualization
**Created:** [May 20, 2021, 4:23am UTC](https://discourse.julialang.org/t/generating-vertices-of-a-simplex/61495 "2021-05-20T04:23:00Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![grero](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/grero/32/109_2.png) [@grero](https://discourse.julialang.org/u/grero)
#### Post date: [May 20, 2021, 4:23am UTC](https://discourse.julialang.org/t/generating-vertices-of-a-simplex/61495/1 "2021-05-20T04:23:00Z")

</div>

For a model I’ve been working on I needed to generate points (cluster centres) that were located equidistant from each other. Not a terribly hard problem, but I happen to come across [this](https://mathoverflow.net/a/184585) answer on mathoverflow that I found pretty neat. I readily admit that I don’t understand exactly how it works, but here is the equivalent julia code:

```julia
"""
Return the vertices of a regular simplex in `n` dimenions.
"""
function get_simplex_vertices(n)
    q,r = qr(fill(1.0, n+1))
    points = permutedims(q[:,2:end],[2,1])
    #rescale so that the distance is 1
    points ./= sqrt(2)
end

```

Just thought I’d put it out there in case anyone else finds it useful at some point.

---

<div class="post-metadata">

### Author: ![Wei\_Yang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wei_yang/32/23951_2.png) [@Wei\_Yang](https://discourse.julialang.org/u/Wei_Yang)
#### Post date: [May 20, 2021, 5:07am UTC](https://discourse.julialang.org/t/generating-vertices-of-a-simplex/61495/2 "2021-05-20T05:07:32Z")

</div>

> q,r = qr(fill(1.0, n+1))

- q is a unitary matrix, with the first column having constant entries (n+1)^{-1/2}
- All columns of q are pairwise orthogonal, and of norm 1.
- Let c\_1, c\_2 be two columns, since they are orthogonal, dist(c\_1,c\_2)= \sqrt{1+1}=\sqrt{2}

> points ./= sqrt(2)

- Thus the above line is just to make sure that the pair-wise distances are 1.

I don’t think dropping the first column is special, you could drop any of the columns.

---

<div class="post-metadata">

### Author: ![grero](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/grero/32/109_2.png) [@grero](https://discourse.julialang.org/u/grero)
#### Post date: [May 20, 2021, 5:09am UTC](https://discourse.julialang.org/t/generating-vertices-of-a-simplex/61495/3 "2021-05-20T05:09:28Z")

</div>

Thanks for the explanation! Now it makes sense : )
