open_curve: Curved Interpolation

Description Usage Arguments Value Examples

View source: R/cspline.R

Description

Interpolate between ordered 2-d points with a smooth curve. open_curve() produces an open curve; closed_curve() produces a closed curve. Bezier curves are also provided.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
open_curve(x, y = NULL, n = 100 * length(z), asp = 1, ...)

## S3 method for class 'curve'
plot(x, y = NULL, type = "l", lty = "solid", ...)

## S3 method for class 'curve'
points(x, pch = 20, ...)

## S3 method for class 'curve'
lines(x, ...)

closed_curve(x, y = NULL, n0 = 100 * length(z0), ...)

bezier_curve(x, y = NULL, n = 500, t = seq(0, 1, length.out = n), ...)

Arguments

x, y

Any of the forms used to specify a 2-d set of points or an object of class "curve"

n, n0

number of points in the interpolating curve

asp

the relative scale for x versus that of y

...

additional arguments currently ignored

pch, type, lty

plot arguments or traditional graphics parameters

t

for Bezier curves, parameter value sequence ranging from 0 to 1

Value

a list with components x, y, and points, of S3 class "curve"

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
oldPar <- par(pty = "s", mfrow = c(2, 2), mar = c(1,1,2,1), xpd = NA)
z <- (complex(argument = seq(-0.9*base::pi, 0.9*base::pi, length = 20)) +
     complex(modulus = 0.125, argument = runif(20, -base::pi, base::pi))) *
     complex(argument = runif(1, -base::pi, base::pi))

plot(z, asp=1, axes = FALSE, ann = FALSE, panel.first = grid())
title(main = "Open")
segments(Re(z[1]), Im(z[1]), Re(z[20]), Im(z[20]), col = "grey", lty = "dashed")
lines(open_curve(z), col = "red")

plot(z, asp=1, axes = FALSE, ann = FALSE, panel.first = grid())
title(main = "Closed")
lines(closed_curve(z), col = "royal blue")

plot(z, asp=1, axes = FALSE, ann = FALSE, panel.first = grid())
title(main = "Bezier")
lines(bezier_curve(z), col = "dark green")

plot(z, asp=1, axes = FALSE, ann = FALSE, panel.first = grid())
title(main = "Circle")
lines(complex(argument = seq(-base::pi, base::pi, len = 500)),
      col = "purple")

par(oldPar)

frenchCurve documentation built on July 1, 2020, 6:27 p.m.