Description Usage Arguments Value Author(s) Examples
Generates points on a sphere. Attempts to regularly distribute
approximately n
points on the surface of a unit sphere
non-iteratively by laying them out along a spiral with a fixed
(angular) pitch.
1 2 | ## Default S3 method:
pointsOnSphere(n=1000, radius=1, ...)
|
n |
The number of points generated. |
radius |
The radius of the sphere. |
... |
Not used. |
Returns a list
of
x
, y
, z
- cartesian coordinates of the points,
theta
- their longitude,
phi
- their lattitude (in radians),
c
- the fixed (angular) pitch used, and
radius
- the radius of the sphere.
Mike Lonergan, mel@mcs.st-and.ac.uk. Adapted by Henrik Bengtsson (http://www.braju.com/R/).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | nearest <- function(xyz) {
# Takes a list with columns x, y, z and returns the (straightline)
# nearest neighbour distances between the points in its rows.
# Inefficient, but adequate for checking pointsOnSphere().
res <- NA
for (i in 1:length(xyz$x)) {
res[i] <- sqrt(min((xyz$x[-i]-xyz$x[i])^2 + (xyz$y[-i]-xyz$y[i])^2 +
(xyz$z[-i]-xyz$z[i])^2))
}
res
}
xyz <- pointsOnSphere(1000)
nxyz <- nearest(xyz)
layout(matrix(1:4, nrow=2, byrow=TRUE))
plot3d(xyz$x, xyz$y, xyz$z, main="3D view")
plot(nxyz, ylab="nearest neighbour distances",xlab="theta")
plot(xyz$x+sign(xyz$z),xyz$y, main="plan view")
plot(xyz$x+sign(xyz$y),xyz$z, main="side.view")
#hist(nxyz, main="nearest neighbour distances")
print(length(which(nxyz<0.06)))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.