Rotate a set of XY coordinates by an angle (in radians)
rotation(xy, angle)
A 2-columns matrix of the same size as xy
giving the rotated
coordinates.
### Create a set of coordinates
coords<-cbind(runif(20),runif(20))
### Create a series of angles
rad<-seq(0,pi,l=20)
for(i in rad){
coords.rot<-rotation(coords,i)
plot(coords.rot)
}
### Rotate the coordinates by an angle of 90 degrees
coords.90<-rotation(coords,90*pi/180)
coords.90
#> [,1] [,2]
#> [1,] -0.532471697 0.27993492
#> [2,] -0.434267697 0.83674747
#> [3,] -0.056031184 0.38146951
#> [4,] -0.537143498 0.35132648
#> [5,] -0.379528326 0.59215392
#> [6,] -0.132407426 0.09548337
#> [7,] -0.516531490 0.24721465
#> [8,] -0.568030388 0.69763835
#> [9,] -0.592261086 0.43338319
#> [10,] -0.776574370 0.14575155
#> [11,] -0.542419303 0.16660655
#> [12,] -0.314120115 0.33550822
#> [13,] -0.059011557 0.75009181
#> [14,] -0.999879470 0.47346740
#> [15,] -0.357859219 0.04091285
#> [16,] -0.778638034 0.98799930
#> [17,] -0.756364372 0.55182791
#> [18,] -0.167400552 0.66252009
#> [19,] -0.606380475 0.57186435
#> [20,] -0.008575765 0.53205383
plot(coords,xlim=range(rbind(coords.90,coords)[,1]),ylim=range(rbind(coords.90,coords)[,2]),asp=1)
points(coords.90,pch=19)