runif_torus {uniformly}R Documentation

Uniform sampling on/in torus

Description

Uniform sampling on or in a torus (dimension 3).

Usage

runif_on_torus(n, R, r)

runif_in_torus(n, R, r)

Arguments

n

number of simulations

R

major radius

r

minor radius

Value

The simulations in a n times 3 matrix.

Examples

R <- 3; r <- 2
sims_on <- runif_on_torus(50, R = R, r = r)
sims_in <- runif_in_torus(50, R = R, r = r)
library(misc3d)
fx <- function(u,v) (R+r*cos(u)) * cos(v)
fy <- function(u,v) (R+r*cos(u)) * sin(v)
fz <- function(u,v) r*sin(u)
parametric3d(
  fx, fy, fz, umin = 0, umax = 2*pi, vmin = 0, vmax = 2*pi, alpha = 0.3
)
library(rgl)
points3d(sims_on)
points3d(sims_in, color = "red")

[Package uniformly version 0.5.0 Index]