First letters for the first name is “M” and the last name is “A” The following code will build MA:
x <- c(rep(-1,500),
seq(-0.25,-1,length.out=500),
seq(-0.25,0.5,length.out=500),
rep(0.5,500),
seq(1.25,2,length.out=500),
seq(1.6,2.4,length.out=500),
seq(2.75,2,length.out=500))
y <- c(seq(-2,1,length.out=500),
seq(-2,1,length.out=500),
seq(-2,1,length.out=500),
seq(-2,1,length.out=500),
seq(-2,1,length.out=500),
rep(-0.7,500),
seq(-2,1,length.out=500))
z=rbind(x,y)
plot(y~x, xlim=c(-3,3), ylim=c(-3,3))
sq_mtx_mlt <- function(x,y){
x %*% y
}
Shearing by taking the identity matrix and replacing one of the zero elements with a non-zero value:
for (i in seq(0,1,length.out=20)) {
z1<-apply(z,2,function(x) sq_mtx_mlt(x,matrix(c(1,i,0,1),nrow=2,ncol=2)))
plot(z1[2,]~z1[1,], xlim=c(-3,3), ylim=c(-3,3))
}
Scaling by multiplication of the values:
for (i in seq(1,3,length.out=20)) {
z1<-apply(z,2,function(x) sq_mtx_mlt(x,matrix(c(i,0,0,i),nrow=2,ncol=2)))
plot(z1[2,]~z1[1,], xlim=c(-3,3), ylim=c(-3,3))
}
Rotating counterclockwise through an angle 360 degrees with respect to the positive x axis about the origin of the two-dimensional system:
for (i in seq(0,pi*2,length.out=20)) {
z1<-apply(z,2,function(x) sq_mtx_mlt(x,matrix(c(cos(i),-sin(i),sin(i),cos(i)),nrow=2,ncol=2)))
plot(z1[2,]~z1[1,], xlim=c(-3,3), ylim=c(-3,3))
}
Projection by rotating around the z-axis:
for (i in seq(0,2*pi,length.out=20)) {
zp<-rbind(z,rep(0,ncol(z)))
z1<-apply(zp,2,function(x) sq_mtx_mlt(x,matrix(c(1,0,0,0,cos(i),-sin(i),0,sin(i),cos(i)),nrow=3,ncol=3)))
plot(z1[2,]~z1[1,], xlim=c(-3,3), ylim=c(-3,3))
}
Reference: 1.https://www.mathsisfun.com/algebra/matrix-transform.html 2.https://www.geeksforgeeks.org/computer-graphics-3d-rotation-transformations/amp/ 3.https://bookdown.org/yihui/rmarkdown-cookbook/animation.html