Rotate a set of XY coordinates by an angle (in radians)
Rotation(xy, angle)
Arguments
xy: A 2-columns matrix or data frame containing a set of X and Y coordinates.
angle: Numeric. A scalar giving the angle at which the points should be rotated. The angle is in radians.
Returns
A 2-columns matrix of the same size as xy giving the rotated coordinates.
Author(s)
F. Guillaume Blanchet
Examples
set.seed(1)### Create a set of coordinatescoords <- cbind(runif(20), runif(20))### Create a series of anglesrad <- seq(0, pi, l=20)opar <- par(mfrow=c(5,4), mar=c(3,3,1,1))for(i in rad){ coords.rot <- Rotation(coords, i) plot(coords.rot, xlab="", ylab="")}par(opar)### Rotate the coordinates by an angle of 90 degreescoords.90<- Rotation(coords,90*pi/180)coords.90plot(coords, xlim=range(rbind(coords.90,coords)[,1]), ylim=range(rbind(coords.90,coords)[,2]), asp=1)points(coords.90, pch=19)