Learn R Programming

uniformly (version 0.5.0)

runif_triangle: Uniform sampling on/in a triangle

Description

Uniform sampling on or in a triangle (dimension 2).

Usage

runif_in_triangle(n, v1, v2, v3)

runif_on_triangle(n, v1, v2, v3)

Value

The simulations in a n times 2 matrix.

Arguments

n

number of simulations

v1, v2, v3

vertices of the triangle

Examples

Run this code
sims <- runif_on_triangle(30, c(0,0), c(1,0), c(0,1))
plot(sims, xlim = c(0,1), ylim = c(0,1), pch = 19)
sims <- runif_in_triangle(100, c(0,0), c(1,0), c(0,1))
plot(sims, xlim = c(0,1), ylim = c(0,1), pch = 19)

Run the code above in your browser using DataLab