runif_torus: Uniform sampling on/in torus

runif_torusR 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")

uniformly documentation built on March 18, 2022, 6:44 p.m.