dimanche 7 avril 2019

randomly generate points within specific sphere coordinates in R

I have specific x,y coordinates. I want to generate random points within a sphere given x as the center and y as the edge of the radius (therefore the distance from x to y would be the length of the radius of the sphere).

I've seen a lot of discussion about how to do this appropriately mathematically (randomly distribute the points to avoid clustering) and was able to compile the easiest examples here and here for sample R code.

I also found this [R package sphereplot] (https://cran.r-project.org/web/packages/sphereplot/sphereplot.pdf) which might be easier, but am having a hard time understanding how to apply it.

These are all good starting points but using the sample code below I'm unsure how to apply it to specific starting points/spherical coordinates?

set.seed(101)
n <- 50
theta <- runif(n,0,2*pi)
u <- runif(n,-1,1)
x <- sqrt(1-u^2)*cos(theta)
y <- sqrt(1-u^2)*sin(theta)
z <- u

Using just one set/row of x,y coordinates from my data frame:

x= -0.0684486861
y = 0.0125857380

I want x to be the center of the circle and the distance to y to be the radius length. Then generate random points from within the sphere with x as the center.

Thanks for the guidance.




Aucun commentaire:

Enregistrer un commentaire