Question: Python help with images. Need procedures that will rotate. ##Problem 1 def rotation(theta): ''' Input: theta, the angle (in radians) to rotate an image. Output:
Python help with images. Need procedures that will rotate.
##Problem 1 def rotation(theta): ''' Input: theta, the angle (in radians) to rotate an image. Output: Corresponding 3x3 rotation matrix. Note that the math module is imported.
>>> def normsq(v): return v*v >>> (rotation(math.pi) * Vec({'x','y','u'},{'x':1,'y':2,'u':1}) - Vec({'x','y','u'},{'x': -1, 'y': -2, 'u': 1})).is_almost_zero() True >>> (rotation(math.pi/2) * Vec({'x','y','u'},{'x':3,'y':1,'u':1}) - Vec({'x','y','u'},{'x': -1, 'y': 3, 'u': 1})).is_almost_zero() True (rotation(3*math.pi/4) * Vec({'x','y','u'},{'x':4,'y':-3,'u':1}) - Vec({'x','y','u'},{'x':-1/math.sqrt(2), 'y':7/math.sqrt(2), 'u': 1})).is_almost_zero() True '''
##Problem 2 def rotate_about(theta, x, y): ''' Input: an angle theta (in radians) by which to rotate, and x- and y- coordinates of a point to rotate about Output: Corresponding 3x3 rotation matrix. It might be helpful to use procedures you already wrote. >>> rotate_about(3,4, math.pi/3)*Vec({'x','y','u'}, {'x':1, 'y':0, 'u':1}) == Vec({'y', 'x', 'u'},{'y': 0.26794919243112214, 'x': 5.4641016151377535, 'u': 1}) True '''
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
