1. Geometric Transformation of Shapes Using Matrix Multiplication

Context:

In computer graphics and data visualization, geometric transformations are fundamental. These transformations, such as translation, scaling, rotation, and reflection, can be applied to shapes to manipulate their appearance.

Task:

Create a simple shape (like a square or triangle) using point plots in R. Implement R code to apply different transformations (scaling, rotation, reflection) to the shape by left multiplying a transformation matrix by each of the point vectors. Demonstrate these transformations through animated plots.

Create a Shape:

Define a simple shape (e.g., a square) using a set of point coordinates. I made sure the aspect ratio was 1:1 using the “asp” parameter for the plot() function.

rm(list = ls())

x=c(rep(0,500),seq(0.65,0.85,length.out=1000), seq(0.75,1,length.out=500), seq(0.5,0.75,length.out=500), seq(-1,0,length.out=500))
y=c(seq(-0.5,1,length.out=500),rep(0,1000), seq(1,-1,length.out=500), seq(-1,1,length.out=500), -0.5-sqrt(0.25-(seq(-1,1,length.out=500)-0.50)^2))
## Warning in sqrt(0.25 - (seq(-1, 1, length.out = 500) - 0.5)^2): NaNs produced
z <- rbind(x, y)

# Create a plot
plot(y~x, xlim=c(-3,3), ylim=c(-3,3), asp = 1)