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.01442019 0.8353889
#> [2,] -0.52052835 0.8915978
#> [3,] -0.97970545 0.3290638
#> [4,] -0.99737918 0.4961151
#> [5,] -0.50255179 0.1340005
#> [6,] -0.55999583 0.1774514
#> [7,] -0.54345446 0.1532729
#> [8,] -0.57487262 0.5140753
#> [9,] -0.01150620 0.7526104
#> [10,] -0.61339353 0.2394357
#> [11,] -0.81585678 0.1137757
#> [12,] -0.69323587 0.2674675
#> [13,] -0.76533459 0.5524454
#> [14,] -0.59164120 0.2855689
#> [15,] -0.70503807 0.5669307
#> [16,] -0.39984095 0.9861353
#> [17,] -0.96883018 0.9502077
#> [18,] -0.75281137 0.5425650
#> [19,] -0.75103572 0.8180132
#> [20,] -0.35387666 0.1371278
plot(coords,xlim=range(rbind(coords.90,coords)[,1]),ylim=range(rbind(coords.90,coords)[,2]),asp=1)
points(coords.90,pch=19)