213 - Linear Transformation Example

37 days ago by Professor213

# Put your transformation matrices successively it the matrices A, B, and C. # Easily create more if desired and add to the code. # For this example, we want to reflect across the line y = (rise/run)x # or perhaps said as "the line created by the vector <5,6> through the origin" # This requires one to rotate counterclockwise by the angle -theta found using trig # and then flipping easily across the x-axis which is well known # and then rotating back clockwise by the angle theta. # Since sine is an odd function, then this has been implememted below by fixing the # correct +/- on the s portions. # The illustration below takes the letter "J" and puts is somewhere originally in BLUE. # The rotation by -theta shows up in RED # The subsequent reflection across the x-axis shows up in GREEN # The rotation back by theta shows up finally in BLACK # If given a vector to refect across, the vector will be given as <run, rise> rise=8 run=3 theta = atan(rise/run) c = cos(theta) s = sin(theta) A = matrix([[c, s],[-s, c]]) B = matrix([[1, 0],[0, -1]]) C = matrix([[c, -s],[s, c]]) # Enter your data points below with x in first and y in second in order pts = matrix([[2.6, 2.8, 3, 3.2, 3.4, 3, 3, 2.9, 2.8, 2.7], [ 1, 1, 1, 1, 1, 0.8, 0.6, 0.5, 0.4, 0.5]]) n = pts.ncols() ans1 = A*pts ans2 = B*ans1 ans3 = C*ans2 T = C*B*A show(A) show(B) show(C) show(T) G = line([(-run,-rise),(run,rise)],color='yellow') for k in range(n): G += point((pts[0][k],pts[1][k]),color='blue') G += point((ans1[0][k],ans1[1][k]),color='red') G += point((ans2[0][k],ans2[1][k]),color='green') G += point((ans3[0][k],ans3[1][k]),color='black') G += line([(ans3[0][k],ans3[1][k]),(pts[0][k],pts[1][k])],alpha=0.4,color='lightgray') G.set_aspect_ratio(1) G.show(figsize=(10,10)) 
       

                                
                            

                                
# THIS IS A PLAYGROUND! :) # Put your transformation matrices successively it the matrices A, B, and C. # Easily create more if desired and add to the code. Use the Indentity if you don't want to delete one. A = matrix([[1, 0],[0, -1]]) B = matrix([[0, -1],[-1, 0]]) C = matrix([[1, 0],[0, 1]]) # Enter your data points below with x in first and y in second in order pts = matrix([[2.6, 2.8, 3, 3.2, 3.4, 3, 3, 2.9, 2.8, 2.7, -1.0], [ 1, 1, 1, 1, 1, 0.8, 0.6, 0.5, 0.4, 0.5, 2.0]]) n = pts.ncols() ans1 = A*pts ans2 = B*ans1 ans3 = C*ans2 T = C*B*A show(A) show(B) show(C) show(T) G = Graphics() # G += line([(-run,-rise),(run,rise)],color='yellow') for k in range(n): G += point((pts[0][k],pts[1][k]),color='blue') G += point((ans1[0][k],ans1[1][k]),color='red') G += point((ans2[0][k],ans2[1][k]),color='green') G += point((ans3[0][k],ans3[1][k]),color='black') G += line([(ans3[0][k],ans3[1][k]),(pts[0][k],pts[1][k])],alpha=0.4,color='lightgray') G.set_aspect_ratio(1) G.show(figsize=(10,10))