Learn R Programming

textures (version 0.1.0)

quad_index: Quad mesh primitives

Description

Generate the components of a quad mesh from the compact specification of a regular grid: the dimension (number of cells nx, ny) and optionally the extent (xmin, xmax, ymin, ymax).

Usage

quad_index(dimension, ydown = FALSE)

quad_edges(dimension, extent = NULL, ydown = FALSE)

quad_vertex(dimension, extent = NULL, ydown = FALSE)

Value

quad_index() a 4-row matrix of vertex indexes (integer, or double for very large grids), quad_edges() a list with x and y

edge coordinate vectors, quad_vertex() a 2-column matrix of vertex coordinates @family textures

Arguments

dimension

number of cells in the grid (nx, ny), a single value is recycled

ydown

should the y coordinate be counted from the top (image/raster orientation), default FALSE

extent

extent of the grid c(xmin, xmax, ymin, ymax), default is the unit square

Details

quad_index() gives the index of the four corner vertices of every cell, a 4 x (nx * ny) matrix of 1-based vertex indexes. Quads are in cell order, x fastest (the matrix() and image() convention, and raster cell order when ydown = TRUE). Winding is counter-clockwise for y-up grids.

quad_edges() gives the unexpanded form of the vertices, the x and y coordinates of the cell edges as two vectors of length nx + 1 and ny + 1. This is the compact intermediate: the full vertex set is their outer expansion, and for many purposes (transform bounds, axis coordinates, texture alignment) the margins are all that is needed.

quad_vertex() gives the materialized vertices, a (nx + 1) * (ny + 1) row matrix of x, y coordinates, x fastest, matching the index in quad_index().

For very large grids where the vertex count or index length exceeds the integer maximum, quad_index() returns a matrix of doubles (exact for integer values to 2^53), which R subsetting and 'mesh3d' usage accept natively. Take care not to apply as.integer() to such an index.

Examples

Run this code
quad_index(c(2, 3))
quad_edges(c(2, 3), extent = c(0, 10, 0, 20))
quad_vertex(c(2, 3), extent = c(0, 10, 0, 20))

Run the code above in your browser using DataLab