R: Draw a Bezier Curve

grid.bezier {grid} | R Documentation

## Draw a Bezier Curve

### Description

These functions create and draw Bezier Curves (a curve drawn relative to 4 control points).

### Usage

    grid.bezier(...)
    bezierGrob(x = c(0, 0.5, 1, 0.5), y = c(0.5, 1, 0.5, 0),
                id = NULL, id.lengths = NULL,
                default.units = "npc", arrow = NULL,
                name = NULL, gp = gpar(), vp = NULL)

### Arguments

`x` | A numeric vector or unit object specifying x-locations of spline control points.
`y` | A numeric vector or unit object specifying y-locations of spline control points.
`id` | A numeric vector used to separate locations in `x` and `y` into multiple beziers. All locations with the same `id` belong to the same bezier.
`id.lengths` | A numeric vector used to separate locations in `x` and `y` into multiple bezier. Specifies consecutive blocks of locations which make up separate beziers.
`default.units` | A string indicating the default units to use if `x` or `y` are only given as numeric vectors.
`arrow` | A list describing arrow heads to place at either end of the bezier, as produced by the `arrow` function.
`name` | A character identifier.
`gp` | An object of class `gpar`, typically the output from a call to the function `gpar`. This is basically a list of graphical parameter settings.
`vp` | A Grid viewport object (or NULL).
`...` | Arguments to be passed to `bezierGrob`.

### Details

Both functions create a beziergrob (a graphical object describing a Bezier curve), but only `grid.bezier` draws the Bezier curve.

A Bezier curve is a line drawn relative to 4 control points.

Missing values are not allowed for `x` and `y` (i.e., it is not valid for a control point to be missing).

The curve is currently drawn using an approximation based on X-splines.

### Value

A grob object.

### See Also

Grid, `viewport`, `arrow`.

`grid.xspline`.

### Examples

    x <- c(0.2, 0.2, 0.4, 0.4)
    y <- c(0.2, 0.4, 0.4, 0.2)

    grid.newpage()
    grid.bezier(x, y)
    grid.bezier(c(x, x + .4), c(y + .4, y + .4),
                id=rep(1:2, each=4))
    grid.segments(.4, .6, .6, .6)
    grid.bezier(x, y,
                gp=gpar(lwd=3, fill="black"),
                arrow=arrow(type="closed"),
                vp=viewport(x=.9))

[Package grid version 3.1.2 Index]