Skip to content

Instantly share code, notes, and snippets.

@dwinter
Last active January 9, 2019 21:34
Show Gist options
  • Save dwinter/56524119a014f886755470be3fd4729c to your computer and use it in GitHub Desktop.
Save dwinter/56524119a014f886755470be3fd4729c to your computer and use it in GitHub Desktop.
uniform sampling on a (half) disk
sample_half_disk <- function(n,radius) {
prop_radius <- runif(n)
angles <- runif(n,0,360)
data.frame( x= sqrt(prop_radius) * cos(angles) * radius,
y = -abs(sqrt(prop_radius) * sin(angles) * radius))
}
plot(sample_half_disk(1e4,300))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment