Sharedtransformation.ipynbOpen in CoCalc

Transformation

Sam Su

2/8/2018

# Create a polygon with given points.
p1 = vector([0,0])
p2 = vector([0,1])
p3 = vector([1,1])
P = polygon([p1,p2,p3])
show(P)
# Shear transformation
A = Matrix([[1,3],[0,1]])
Q = polygon([A*p1,A*p2,A*p3],color="green")
show(P+Q)
# Translation
v = vector([2,1])
Q = polygon([p1+v,p2+v,p3+v],color="green")
show(P+Q)
# Rotation
theta = pi/6
A = Matrix([[cos(theta),-sin(theta)],[sin(theta),cos(theta)]])
Q = polygon([A*p1,A*p2,A*p3],color="green")
show(P+Q)
# Reflection
theta = pi/6
A = Matrix([[cos(2*theta),sin(2*theta)],[sin(2*theta),-cos(2*theta)]])
Q = polygon([A*p1,A*p2,A*p3],color="green")
show(P+Q)
# Scaling
A = Matrix([[2,0],[0,1/3]])
Q = polygon([A*p1,A*p2,A*p3],color="green")
show(P+Q)