##################### # Rotating triangle # ##################### # for more fun, check out https://www.youtube.com/watch?v=sW9npZVpiMI x = c(0, 2, 3) y = c(0, 7, 5) oldtriangle = rbind(x,y) theta = pi/2 rotate.matrix = matrix(c(cos(theta),-sin(theta),sin(theta),cos(theta)),nrow=2,byrow=T) newtriangle = rotate.matrix%*%oldtriangle plot(x, y, type = "p", pch = 16, col = "blue", xlim = c(-7, 7), ylim = c(-7, 7)) polygon(x, y, col = "red", border = "blue") polygon(newtriangle[1,], newtriangle[2,], col = "black", border = "green")