## a random triangle in [0,1]^2:
P <- matrix(runif(6), 3, 2)
## n points uniformly distributed in the triangle P:
n <- 10000
x <- rpit(n, P)
layout(matrix(1:2, 1))
plot(P, type = "n", asp = 1)
polygon(P, col = "yellow", border = NA)
points(x, pch = ".", col = "blue")
## using Beta distributions:
foo <- function(n) rbeta(n, 1, 10)
bar <- function(n) rbeta(n, 1, 1)
y <- rpit(n, P, foo, bar)
plot(P, type = "n", asp = 1)
polygon(P, col = "yellow", border = NA)
points(y, pch = ".", col = "blue")
layout(1)
Run the code above in your browser using DataLab