Skip to content

Commit

Permalink
pentagram example
Browse files Browse the repository at this point in the history
  • Loading branch information
stla committed Nov 3, 2023
1 parent 9bdcd3b commit 58fe53f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 15 deletions.
16 changes: 16 additions & 0 deletions R/interpolators.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ iprBarycentricRational <- function(x, y, ao = 3) {
#' head(Curve)
#' plot(Curve, type = "l", lwd = 2)
#' points(points, pch = 19)
#'
#' # a closed example (pentagram) ####
#' rho <- sqrt((5 - sqrt(5))/10)
#' R <- sqrt((25 - 11*sqrt(5))/10)
#' points <- matrix(NA_real_, nrow = 10L, ncol = 2L)
#' points[c(1, 3, 5, 7, 9), ] <- t(vapply(0:4, function(i){
#' c(rho*cospi(2*i/5), rho*sinpi(2*i/5))
#' }, numeric(2L)))
#' points[c(2, 4, 6, 8, 10), ] <- t(vapply(0:4, function(i){
#' c(R*cospi(2*i/5 + 1/5), R*sinpi(2*i/5 + 1/5))
#' }, numeric(2L)))
#' ipr <- iprCatmullRom(points, closed = TRUE)
#' s <- seq(0, 1, length.out = 400L)
#' Curve <- evalInterpolator(ipr, s)
#' plot(Curve, type = "l", lwd = 2, asp = 1)
#' points(points, pch = 19)
iprCatmullRom <- function(points, closed = FALSE, alpha = 0.5) {
stopifnot(is.matrix(points))
stopifnot(ncol(points) %in% c(2L, 3L))
Expand Down
24 changes: 9 additions & 15 deletions inst/essais/essai04_CatmullRom_pentagram.R
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
library(interpolators)

# a closed example (pentagram) ####
rho <- sqrt((5 - sqrt(5))/10)
vs1 <- t(vapply(0:4, function(i){
c(rho*cos(2*i*pi/5), rho*sin(2*i*pi/5))
}, numeric(2L)))
R <- sqrt((25 - 11*sqrt(5))/10)
vs2 <- t(vapply(0:4, function(i){
c(R*cos(2*i*pi/5 + pi/5), R*sin(2*i*pi/5 + pi/5))
}, numeric(2L)))
points <- matrix(NA_real_, nrow = 10L, ncol = 2L)
points[c(1, 3, 5, 7, 9),] <- vs1
points[c(2, 4, 6, 8, 10),] <- vs2




ipr <- iprCatmullRom(points, closed = TRUE, alpha = 1)
s <- seq(0, 1, length.out = 400)
points[c(1, 3, 5, 7, 9), ] <- t(vapply(0:4, function(i){
c(rho*cospi(2*i/5), rho*sinpi(2*i/5))
}, numeric(2L)))
points[c(2, 4, 6, 8, 10), ] <- t(vapply(0:4, function(i){
c(R*cospi(2*i/5 + 1/5), R*sinpi(2*i/5 + 1/5))
}, numeric(2L)))
ipr <- iprCatmullRom(points, closed = TRUE)
s <- seq(0, 1, length.out = 400L)
Curve <- evalInterpolator(ipr, s)
head(Curve)
plot(Curve, type = "l", lwd = 2, asp = 1)
points(points, pch = 19)

Expand Down
16 changes: 16 additions & 0 deletions man/iprCatmullRom.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 58fe53f

Please sign in to comment.