Learn R Programming

secr (version 5.0.0)

transformations: Transform Point Array

Description

Flip (reflect), rotate or slide (translate) an array of points. Methods are provided for `traps' objects that ensure other attributes are retained. The methods may be used with rbind.traps to create complex geometries.

Usage

flip (object, lr = FALSE, tb = FALSE, ...)
rotate (object, degrees, centrexy = NULL, ...)
shift (object, shiftxy, ...)

# S3 method for traps flip (object, lr = FALSE, tb = FALSE, ...) # S3 method for traps rotate(object, degrees, centrexy = NULL, ...) # S3 method for traps shift(object, shiftxy, ...)

# S3 method for popn flip (object, lr = FALSE, tb = FALSE, ...) # S3 method for popn rotate(object, degrees, centrexy = NULL, ...) # S3 method for popn shift(object, shiftxy, ...)

# S3 method for mask shift(object, shiftxy, ...)

Value

A matrix or object of class `traps' or `popn' with the coordinates of each point transformed as requested.

Arguments

object

a 2-column matrix or object that can be coerced to a matrix

lr

either logical for whether array should be flipped left-right, or numeric value for x-coordinate of axis about which it should be flipped left-right

tb

either logical for whether array should be flipped top-bottom, or numeric value for y-coordinate of axis about which it should be flipped top-bottom

degrees

clockwise angle of rotation in degrees

centrexy

vector with xy coordinates of rotation centre

shiftxy

vector of x and y displacements

...

other arguments (not used)

Details

flip reflects points about a vertical or horizontal axis. Logical values for lr or tb indicate that points should be flipped about the mean on the relevant axis. Numeric values indicate the particular axis value(s) about which points should be flipped. The default arguments result in no change.

shift shifts the location of each point by the desired amount on each axis.

rotate rotates the array about a designated point. If centrexy is NULL then rotation is about (0,0) (rotate.default), the array centre (rotate.traps), or the centre of the bounding box (rotate.popn).

See Also

traps, popn

Examples

Run this code

temp <- matrix(runif (20) * 2 - 1, nc = 2)

## flip
temp2 <- flip(temp, lr = 1)
plot(temp, xlim=c(-1.5,4), ylim = c(-1.5,1.5), pch = 16)
points (temp2, pch = 1)
arrows (temp[,1], temp[,2], temp2[,1], temp2[,2], length = 0.1)
abline(v = 1, lty = 2)

## rotate
temp2 <- rotate(temp, 25)
plot(temp, xlim=c(-1.5,1.5), ylim = c(-1.5,1.5), pch = 16)
points (0,0, pch=2)
points (temp2, pch = 1)
arrows (temp[,1], temp[,2], temp2[,1], temp2[,2], length = 0.1)	

## shiftxy
temp2 <- shift(temp, c(0.1, 0.1))
plot(temp, xlim=c(-1.5,1.5), ylim = c(-1.5,1.5), pch = 16)
points (0,0, pch=2)
points (temp2, pch = 1)
arrows (temp[,1], temp[,2], temp2[,1], temp2[,2], length = 0.1)	

## flip.traps
par(mfrow = c(1,2), xpd = TRUE)
traps1 <- make.grid(nx = 8, ny = 6, ID = "numxb")
traps2 <- flip (traps1, lr = TRUE)
plot(traps1, border = 5, label = TRUE, offset = 7, gridl = FALSE)
plot(traps2, border = 5, label = TRUE, offset = 7, gridl = FALSE)
par(mfrow = c(1,1), xpd = FALSE)

## rotate.traps
hollow1 <- make.grid(nx = 8, ny = 8, hollow = TRUE)
nested <- rbind (hollow1, rotate(hollow1, 45, c(70, 70)))
plot(nested, gridlines = FALSE)

## shift.traps
hollow1 <- make.grid(nx = 8, ny = 8, hollow = TRUE)
hollow2 <- shift(make.grid(nx = 6, ny = 6, hollow = TRUE), c(20, 20))
nested <- rbind (hollow1, hollow2)
plot(nested, gridlines = FALSE, label = TRUE)

Run the code above in your browser using DataLab