comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » equally spaced points on a hypersphere?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: equally spaced points on a hypersphere? [message #41524 is a reply to message #41449] Mon, 01 November 2004 05:34 Go to previous messageGo to previous message
robert.dimeo is currently offline  robert.dimeo
Messages: 42
Registered: November 2001
Member
James,

Thanks very much for your solution. This is exactly what I was
looking for. The function below implements the steps outlined in your
posting.

Rob

function create_simplex,ndim,center = center,radius = radius
; Uses a technique suggested by James Kuyper to
; create an equilateral simplex in n-dimensions. The return
; value is an array ndim by ndim+1. The coordinates of
; the i-th vertex of the simplex are obtained as
; p[*,i] such as in the following call:
; IDL> p = create_simplex(5) ; create a 5-d simplex
; IDL> vertex_3 = p[*,2] ; the 3rd vertex in the 5-d simplex
;
p = dblarr(ndim,ndim+1)
if n_elements(center) eq 0 then center = dblarr(ndim)
if n_elements(radius) eq 0 then radius = 1d

; Fill in the values for n = 2
p[0,0] = -sqrt(3.)/2. & p[1,0] = -0.5
p[0,1] = sqrt(3.)/2. & p[1,1] = -0.5
p[1,2] = 1.
if ndim gt 2 then begin
for j = 3,ndim do begin
; Solve for the value of the new dimension
p[j-1,j] = sqrt(total((p[0:j-1,1]-p[0:j-1,0])^2)-1d)
; Find the center
pc = dblarr(j)
for i = 0,j-1 do pc[i] = (moment(p[i,0:j]))[0]
; Subtract the center from each of the points
; in the simplex so that it is centered at 0
for k = 0,j do p[0:j-1,k] = p[0:j-1,k] - pc[0:j-1]
; Now find the normalization constant for unit radius
; of the hypersphere
norm = sqrt(total(p[*,0]^2))
p = temporary(p)/norm
endfor
endif
; Scale the simplex
p = p*radius
; Shift the center
for i = 0,ndim-1 do p[i,*] = p[i,*]+center[i]
return,p
end

James Kuyper <kuyper@saicmodis.com> wrote in message news:<41827538.4050709@saicmodis.com>...
>
>
> For n=1, the solution is two points at +/-1.
>
> For n>1, take the solution for n-1 dimensions, centered at the origin.
> Add one dimension, and give all those points a value of 0 in the new
> dimension. Add a point with a value of 'x' for the new dimension, with
> all it's other coordinates set to 0. Calculate the distance of the new
> point from any of the old points, as a function of 'x'. Solve for the
> value of 'x' that puts the new point at the same distance from the old
> point, as the old point was from all of the other points. By symmetry,
> the new point will also be that same distance from all of the other old
> points. Find the center of the new set of points. Shift all the points
> by the amount needed to center them on the desired location. Shift all
> of the points outward from the center by the same factor, to get a
> hypersphere of the desired radius.
>
> Example, for n=2:
>
> Start with two points a <-1,0> and <+1,0>.
> Add a third point at <0,x>. The distance from first point is
> sqrt(1+x^2). The distance between first two points is 2, so x = sqrt(3).
>
> The center of <-1,0>, <1,0> and <0,sqrt(3)> is at <0, 1/sqrt(3)>.
>
> Shifting all the points to center at 0, we get <-1,-1/sqrt(3)>,
> <1,-sqrt(3)/3> and <0,2/sqrt(3)>. The new circle has a radius of 2/sqrt(3).
>
> Multiply by sqrt(3)/2, to get a circle of radius one, leaving us with
> <-sqrt(3)/2, -1/2>, <sqrt(3)/2, -1/2>, <0,1>.
>
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Complex arguments in Bessel functions
Next Topic: Re: idlhelp copy and paste problem

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sat Oct 11 06:07:40 PDT 2025

Total time taken to generate the page: 2.18235 seconds