Skip to contents

z[i, j] is the value at (xs[j], ys[i]); the contour lines themselves come from IsoLines. ContourFill: isobands between consecutive levels; each cell is split into two triangles (the field is linear on a triangle) and each triangle is clipped to levels[k] <= z < levels[k + 1]; areas are exact for the piecewise-linear interpolant. ContourBands: the isobands with a grey shade per band. ContourClip: polyline pieces inside a convex counter-clockwise polygon (Sutherland and Hodgman 1974). ContourQuantity: area and integral of the field where lower <= z < upper (each clipped polygon is fanned into triangles; the integral of a linear field over a triangle is its area times the mean of the three vertex values). ContourLabels: label at the midpoint of the straightest run of each polyline (smallest neighbouring turning angles, ties to the longest segment) with the text angle along it. ContourSmooth: uniform B-spline through the vertices as control points (de Boor recurrence; clamped knots for open curves, wrapped control points for closed ones).

Usage

ContourFill(z, xs, ys, levels)

ContourBands(z, xs, ys, levels, shades = NULL)

ContourClip(lines, polygon)

ContourQuantity(z, xs, ys, lower, upper)

ContourLabels(lines, min_length = 0)

ContourSmooth(line, degree = 3, samples = 50, closed = FALSE)

Arguments

z

Numeric matrix of field values.

xs, ys

Grid coordinates of the columns and rows of z.

levels

Contour levels (band edges for the fill functions).

shades

Optional shade per band (default grey levels 0.9 to 0.2).

lines

List of polylines, each a two-column matrix of vertices.

polygon

Convex clip polygon, two-column matrix, counter-clockwise.

lower, upper

Band limits for ContourQuantity.

min_length

Polylines shorter than this get no label.

line

One polyline (two-column matrix) to smooth.

degree

B-spline degree.

samples

Number of evaluation points.

closed

Treat the polyline as closed.

Value

A list; see each function.

References

Sutherland, I. E. and Hodgman, G. W. (1974). Reentrant polygon clipping. Communications of the ACM 17, 32-42.

de Boor, C. (1978). A Practical Guide to Splines. Springer.

Examples

z <- rbind(c(0, 1), c(1, 2))
ContourFill(z, c(0, 1), c(0, 1), c(0, 1, 2.5))$areas
#> [1] 0.5 0.5
ContourQuantity(z, c(0, 1), c(0, 1), 0, 3)$integral
#> [1] 1