[R] points on a sphere

Jan de Leeuw deleeuw at stat.ucla.edu
Sat Oct 26 05:17:49 CEST 2002


This puts n points in R^p "as equally spaced as possible". If  
sphere=TRUE
it constrains them to be on the sphere.
============================================================

equidist<-function(n, p, eps=1e-6, itmax=Inf, verbose=TRUE,  
sphere=FALSE) {
x<-matrix(rnorm(n*p),n,p); sprev<-0; itel<-1
if (sphere) x<-row.norm(x) else x<-x/sqrt(sum(x^2))
repeat{
	s<-sum(d<-eudist(x))
	if (verbose) cat(formatC(itel,width=6),
			formatC(s,digits=6,width=20,format="f"),"\n")
	if ((((s-sprev)/sprev) < eps) || (itel == itmax)) return(x)
	diag(d)<-1; e<-1/d; f<-apply(e,1,sum); e<--e; diag(e)<-f
	x<-e%*%x
	if (sphere) x<-row.norm(x) else x<-x/sqrt(sum(x^2))
	sprev<-s; itel<-itel+1
	}
}

row.norm<-function(x) x/sqrt(apply(x^2,1,sum))

eudist<-function(x){
c<-crossprod(t(x)); s<-diag(c)
sqrt(outer(s,s,"+")-2*c)
}

bmat<-function(d,delta,w){
}



On Friday, October 25, 2002, at 04:46 PM, Richard Rowe wrote:

> Not an R question directly, but has anyone got a method for placing a  
> moderately large number of (near) equi-spaced points on a sphere?  I  
> have a nasty feeling platonic solids are needed for exact solutions  
> and I'm thinking of samplings involving around 200 - 1000  
> regularly-spaced points,
>
> Thanks,
>
> Richard Rowe
>
> Richard Rowe
> Senior Lecturer
> Department of Zoology and Tropical Ecology, James Cook University
> Townsville, Queensland 4811, Australia
> fax (61)7 47 25 1570
> phone (61)7 47 81 4851
> e-mail: Richard.Rowe at jcu.edu.au
> http://www.jcu.edu.au/school/tbiol/zoology/homepage.html
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 
> .-.-.-.-.-
> r-help mailing list -- Read  
> http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To:  
> r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ 
> ._._._._
>
>
===
Jan de Leeuw; Professor and Chair, UCLA Department of Statistics;
Editor: Journal of Multivariate Analysis, Journal of Statistical  
Software
US mail: 9432 Boelter Hall, Box 951554, Los Angeles, CA 90095-1554
phone (310)-825-9550;  fax (310)-206-5658;  email: deleeuw at stat.ucla.edu
homepage: http://gifi.stat.ucla.edu
   
------------------------------------------------------------------------ 
-------------------------
           No matter where you go, there you are. --- Buckaroo Banzai
                    http://gifi.stat.ucla.edu/sounds/nomatter.au
   
------------------------------------------------------------------------ 
-------------------------

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list