x=c(rep(0,500),seq(0,1,length.out=1000), rep(1,500))
y=c(seq(-1,1,length.out=500),rep(0,1000), seq(-1,1,length.out=500))
z=rbind(x,y)
plot(y~x, xlim=c(-3,3), ylim=c(-3,3))
I modified the code for building an H in order to build my initials.
x <- c(rep(-2,500), seq(-2,-1,length.out=1000), rep(-1,500), seq(-2,-1,length.out=1000), seq(-2,-1,length.out=1000), seq(0,1,length.out=1000), rep(0, 500), seq(0,1,length.out=1000))
y <- c(seq(0,1,length.out=500), rep(0,1000), seq(-1,0, length.out=500), rep(1,1000), rep(-1,1000), rep(0,1000), seq(-1,1,length.out=500), rep(1,1000))
sf <- rbind(x,y)
plot(y~x, xlim=c(-3,2), ylim=c(-3,3))
leftMultiply <- function (x, y){
x %*% y
}
A shearing transformation causes the object to slant. For matrix [a,b,c,d], changing b or c leads to a shear transformation. Here I changed c to shear in the x direction.
for (i in seq(0,2,length.out=10)) {
shear <- leftMultiply(matrix(c(1,0,i,1),byrow=T,nrow=2), sf)
plot(shear[2,]~shear[1,], xlim=c(-3,2), ylim=c(-5,3))
}
Scaling makes the object bigger or smaller. Here I scaled by the same value along the x and y axes.
for (i in seq(.5,1.5,length.out=10)) {
scale <- leftMultiply(matrix(c(i,0,0,i),byrow=T,nrow=2), sf)
plot(scale[2,]~scale[1,], xlim=c(-3,2), ylim=c(-3,3))
}
Rotation causes the object to rotate around a point. Here, my initials rotate around the z-axis.
for (i in seq(0,2*pi,length.out=10)) {
rotate <- leftMultiply(matrix(c(cos(i),sin(i),-sin(i),cos(i)),byrow=T,nrow=2), sf)
plot(rotate[2,]~rotate[1,], xlim=c(-3,2), ylim=c(-3,3))
}
Projection flattens the image.
A rotation around the x-axis will flatten the image.
project_sf <- rbind(sf, rep(0, ncol(sf)))
for (i in seq(0,2*pi,length.out=5)) {
project <- leftMultiply(matrix(c(1,0,0,0,cos(i),sin(i),0,-sin(i),cos(i)),byrow=T,nrow=3), project_sf)
plot(project[2,]~project[1,], xlim=c(-3,2), ylim=c(-3,3))
}