Draw an Xspline
Description
Draw an Xspline, a curve drawn relative to control points.
Usage
1 2 
Arguments
x,y 
vectors containing the coordinates of the vertices
of the polygon. See 
shape 
A numeric vector of values between 1 and 1, which control the shape of the spline relative to the control points. 
open 
A logical value indicating whether the spline is an open or a closed shape. 
repEnds 
For open Xsplines, a logical value indicating whether the first and last control points should be replicated for drawing the curve. Ignored for closed Xsplines. 
draw 
logical: should the Xspline be drawn? If false, a set of line segments to draw the curve is returned, and nothing is drawn. 
border 
the color to draw the curve. Use 
col 
the color for filling the shape. The default,

... 
graphical parameters such as 
Details
An Xspline is a line drawn relative to control points. For each control point, the line may pass through (interpolate) the control point or it may only approach (approximate) the control point; the behaviour is determined by a shape parameter for each control point.
If the shape parameter is greater than zero, the spline approximates the control points (and is very similar to a cubic Bspline when the shape is 1). If the shape parameter is less than zero, the spline interpolates the control points (and is very similar to a CatmullRom spline when the shape is 1). If the shape parameter is 0, the spline forms a sharp corner at that control point.
For open Xsplines, the start and end control points must have a shape of 0 (and nonzero values are silently converted to zero).
For open Xsplines, by default the start and end control points are
replicated before the curve is drawn. A curve is drawn between
(interpolating or approximating) the second and third of each set of
four control points, so this default behaviour ensures that the
resulting curve starts at the first control point you have specified
and ends at the last control point. The default behaviour can be
turned off via the repEnds
argument.
Value
If draw = TRUE
, NULL
otherwise a list with elements
x
and y
which could be passed to lines
,
polygon
and so on.
Invisible in both cases.
Note
Twodimensional splines need to be created in an isotropic coordinate system. Device coordinates are used (with an anisotropy correction if needed.)
References
Blanc, C. and Schlick, C. (1995), Xsplines : A Spline Model Designed for the End User, in Proceedings of SIGGRAPH 95, pp.\sspace377–386. http://deptinfo.labri.fr/~schlick/DOC/sig1.html
See Also
polygon
.
par
for how to specify colors.
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 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46  ## based on examples in ?grid.xspline
xsplineTest < function(s, open = TRUE,
x = c(1,1,3,3)/4,
y = c(1,3,3,1)/4, ...) {
plot(c(0,1), c(0,1), type = "n", axes = FALSE, xlab = "", ylab = "")
points(x, y, pch = 19)
xspline(x, y, s, open, ...)
text(x+0.05*c(1,1,1,1), y+0.05*c(1,1,1,1), s)
}
op < par(mfrow = c(3,3), mar = rep(0,4), oma = c(0,0,2,0))
xsplineTest(c(0, 1, 1, 0))
xsplineTest(c(0, 1, 0, 0))
xsplineTest(c(0, 1, 1, 0))
xsplineTest(c(0, 0, 1, 0))
xsplineTest(c(0, 0, 0, 0))
xsplineTest(c(0, 0, 1, 0))
xsplineTest(c(0, 1, 1, 0))
xsplineTest(c(0, 1, 0, 0))
xsplineTest(c(0, 1, 1, 0))
title("Open Xsplines", outer = TRUE)
par(mfrow = c(3,3), mar = rep(0,4), oma = c(0,0,2,0))
xsplineTest(c(0, 1, 1, 0), FALSE, col = "grey80")
xsplineTest(c(0, 1, 0, 0), FALSE, col = "grey80")
xsplineTest(c(0, 1, 1, 0), FALSE, col = "grey80")
xsplineTest(c(0, 0, 1, 0), FALSE, col = "grey80")
xsplineTest(c(0, 0, 0, 0), FALSE, col = "grey80")
xsplineTest(c(0, 0, 1, 0), FALSE, col = "grey80")
xsplineTest(c(0, 1, 1, 0), FALSE, col = "grey80")
xsplineTest(c(0, 1, 0, 0), FALSE, col = "grey80")
xsplineTest(c(0, 1, 1, 0), FALSE, col = "grey80")
title("Closed Xsplines", outer = TRUE)
par(op)
x < sort(stats::rnorm(5))
y < sort(stats::rnorm(5))
plot(x, y, pch = 19)
res < xspline(x, y, 1, draw = FALSE)
lines(res)
## the end points may be very close together,
## so use last few for direction
nr < length(res$x)
arrows(res$x[1], res$y[1], res$x[4], res$y[4], code = 1, length = 0.1)
arrows(res$x[nr3], res$y[nr3], res$x[nr], res$y[nr], code = 2, length = 0.1)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker. Vote for new features on Trello.