rm(list=ls())
library(ggplot2)
x<- c(
seq(-2.1,-1.1,length.out=200),
rep(-2.1,200),
seq(-2.1,-1.2,length.out=200),
seq(-1.1,-1.5,length.out=200),
rep(1,200),
rep(-1.1,200),
seq(-1.1,-1.2,length.out=200),
rep(1,200),
seq(1,2,length.out=200),
seq(1,2,length.out=200),
rep(2,200),
seq(1,2,length.out=200))
y<- c(
rep(1,200),
seq(-1,1,length.out=200),
rep(-1,200),
rep(0,200),
seq(0,0,length.out=200),
seq(-1,0,length.out=200),
rep(-1,200),
seq(1,0,length.out=200),
rep(1,200),
rep(0,200),
seq(0,-1,length.out=200),
rep(-1,200))
z <- rbind(x,y)
steps <- 25
wait_t <- 0
plot(y~x, xlim=c(-2,2), ylim=c(-2,2), asp=1)
Basic Transformations. We will apply matrix transformations to our “GS” matrix defined earlier. The transformation we will do will be
Shear Rotation Enlarge Shrink Projection
# Shear
max_shear <- 2
f <- max_shear/steps
x11()
for (i in 0:steps) {
t <- i * f
S <- matrix(c(1,t,0,1),nrow=2, ncol=2, byrow = TRUE)
Transx_Sheared = S %*% z
X <- Transx_Sheared[1,]
Y <- Transx_Sheared[2,]
plot(Y~X, xlim=c(-3,3), ylim=c(-3,3), asp=1)
Sys.sleep(wait_t)
}
max_rotation <- 180 #degrees
f <- max_rotation/steps
x11()
for (i in 0:steps) {
t <- i * f
R <- matrix(c(cos(t * pi / 180),-sin(t * pi / 180),sin(t * pi / 180),cos(t * pi / 180)),nrow=2, ncol=2, byrow = TRUE)
Transx_Rotated <- R %*% z
X <- Transx_Rotated[1,]
Y <- Transx_Rotated[2,]
plot(Y~X, xlim=c(-3,3), ylim=c(-3,3), asp=1)
Sys.sleep(wait_t)
}