Saturday, December 4, 2010

Fun with linear transformation in R



Define a simple plotting function:

f = function(m,v) {
plot(m,xlim=v[1:2],ylim=v[3:4],
col=1:5,pch=16,cex=3,
xlab='x',ylab='y') }
x = seq(0.1,1.0,0.2)
m = cbind(x,x)

Linear transformation as shown above.

limits=c(0,2,0,2)
par(mfrow=c(2,2))
f(m,limits)
T=matrix(c(2,0,0,2),nrow=2)
f(m %*% T,limits)

Rotation of 180°



limits = c(-1,1,-1,1)
par(mfrow=c(2,2))
f(m,limits)
T=matrix(c(0,-1,-1,0),nrow=2)
f(m %*% T,limits)

Rotation by steps




# cex=2
s=1/sqrt(2)
T=matrix(c(s,s,-s,s),nrow=2)
limits = c(-1.4,1.4,-1.4,1.4)

par(mfrow=c(3,3))
f(m,limits)
for (i in 1:8) {
m = m %*% T
f(m,limits)}

No comments: