From: baptiste Auguié <ba208_at_exeter.ac.uk>

Date: Sun, 3 Feb 2008 18:55:30 +0000

R-help_at_r-project.org mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Mon 04 Feb 2008 - 07:40:47 GMT

Date: Sun, 3 Feb 2008 18:55:30 +0000

*> require(rgl)
**> r<-1
**> size<-10
**> theta<-seq(0,2*pi,length=size*2)
**> phi<-seq(0,pi,length=size)
**> pc = as.matrix(rbind(expand.grid(theta,phi)))
**> x<- r* sin(pc[,2]) * cos(pc[,1])
**> y<- r* sin(pc[,2]) * sin(pc[,1])
**> z<- r* cos(pc[,2])
**>
*

> plot3d(x, y, z, col=rainbow(1000), size=2,zlim=c(-1,1)) #

*> scatterplot of points on a sphere
**>
**> df<- unique(rbind(x,y,z), MARGIN = 2 ) # removes duplicates in
**> cartesian coordinates
**> dimension <- dim(df)[1]
**> matDistances <- array(data=0,dim=c(dimension,dimension))
**>
**> norm <- function(a) sqrt(a %*% a)
**>
**> for (ii in 1:dimension){
**> for (jj in ii:dimension){
**> matDistances[ii,jj]<- norm( df[,ii] - df[,jj])
**> }
**> }
*

This is both inefficient and ugly, I'll welcome any suggestion. In particular:

- the location of the points on the sphere is not ideal (understand: not uniformly distributed over the area): i looked into delaunayn from the geometry package and qhull.com but at best I obtained a random set of points on the sphere. It must be a most classical problem –– generating a uniform distribution of points on a sphere––, but i've set that problem aside for the moment.
- the double for loop over all the points cries out for a vectorized solution, but i can't really think of any.

Many thanks in advance,

baptiste

Baptiste Auguié

Physics Department

University of Exeter

Stocker Road,

Exeter, Devon,

EX4 4QL, UK

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag

http://projects.ex.ac.uk/atto

R-help_at_r-project.org mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Mon 04 Feb 2008 - 07:40:47 GMT

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.2.0, at Tue 05 Feb 2008 - 08:30:11 GMT.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*