We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2898f90 commit 157f2cbCopy full SHA for 157f2cb
6.linear-algebra/matrix-tranformations.R
@@ -0,0 +1,31 @@
1
+draw.segment <- function(p1,p2,color,width=3) {
2
+ segments(p1[1],p1[2],p2[1],p2[2], col=color, lwd=width)
3
+}
4
+
5
+plot(NULL,xlim=c(-3,3),ylim=c(-3,3),ylab="y",xlab="x")
6
7
+# draw a segment (initially at 45 degrees)
8
+p.init <- matrix(c(0,0),2,1)
9
+p.end <- matrix(c(2,2),2,1)
10
+draw.segment(p.init, p.end, "red")
11
12
+# rotation example
13
+theta <- pi/4 # rotate more 45º degrees
14
+rotate.matrix <- matrix(c( cos(theta),sin(theta),
15
+ -sin(theta),cos(theta)),2,2)
16
17
+p1.init <- rotate.matrix %*% p.init
18
+p1.end <- rotate.matrix %*% p.end
19
+draw.segment(p1.init, p1.end, "blue")
20
21
+# scaling example
22
+scalingx <- 0.5 # scale both axis by 50%
23
+scalingy <- 0.5
24
+scale.matrix <- matrix(c(scalingx, 0,
25
+ 0, scalingy),2,2)
26
27
+p2.init <- scale.matrix %*% p.init
28
+p2.end <- scale.matrix %*% p.end
29
+draw.segment(p2.init, p2.end, "green")
30
31
0 commit comments