Question
Please I need help, I had posted this twice before but never got an answer. I need help with coding the following assignment. We are
Please I need help, I had posted this twice before but never got an answer.
I need help with coding the following assignment. We are using Python 3.6 to complete this; I have provided starter code but it needs to be edited to have two objects with 6 vertices each. Please help. Thank You!
import matplotlib.pyplot as plt import numpy as np from time import sleep # %%%%%%%%%%%%%%%%%%% # Define function to plot our object (for animations) # - You may change the axis limits for your needs # %%%%%%%%%%%%%%%%%%
def plotmat (M): plt.gcf().clear() # plt.hold(False) plt.plot(np.transpose(M[0,:]),np.transpose(M[1,:])) plt.xlim(-30,30) plt.ylim(-2,50) plt.show()
return;
# %%%%%%%%%%%%%%%%%%% # Define functions for the transformations # %%%%%%%%%%%%%%%%%% # Translation Transformation def translateM (tx, ty): Mout=np.matrix('1 0 %s; 0 1 %s; 0 0 1' % (tx,ty)) return Mout;
# Scaling Transformation
# Rotation around origin Transformation
# Rotation away from origin Transformation
#Reflection over x-axis or y-axis, or both
#Reflection over a line
# Shearing Transformation
# And any transformation I am missing
# %%%%%%%%%%%%%%%%% # Create Your Object # - Store the vertices of the object in a 2 x n matrix where the x coordinates of the vertices are stored in first row and the y coordinates in the second row. # Each successsive pair of points is connected by a straight line. # EXAMPLE: Consider the parallelogram formed by the vertices (2,0), (1,2), (2,4) and (3,2) . # Form Object matrix using vertices as columns and adding starting vector (2,0) onto tail/end (otherwise we would be missing a line) is M=( 2 1 2 3 2; 0, 2, 4, 2 0)
M=np.matrix('2 1 2 3 2; 0, 2, 4, 2 0')
# Add row of ones to M since we need a 3 x n matrix for the translation transformation (projected into R^3 with z=1) onesRow=np.ones(M.shape[1]) M=np.vstack((M,onesRow))
# Initiate Interactive plot plt.ion() plt.show()
# Translate 1 unit in x and 1 in y 10 times T=translateM(1,1) for j in range(0,10): M=T*M plotmat(M) plt.pause(0.4) plotmat(M) plt.pause(1) # Translate for no good reason M=translateM(-3,-8)*M plotmat(M) plt.pause(1) plt.title('Animate Object Example') plt.grid(True)
2. PART II: ANIMATIONS VIA TRANSFORMATIONS 2.1. 2D Animation (1) Create two objects each with at least 6 vertices (2) Animate these objects using (all of the following at least once) Translation Rotation around origin . Rotation about the object itself (away from the origin) Reflect the object over x-axis or y-axis or both Reflect the object over a line (i.e. line y =-x) Shearing 2. PART II: ANIMATIONS VIA TRANSFORMATIONS 2.1. 2D Animation (1) Create two objects each with at least 6 vertices (2) Animate these objects using (all of the following at least once) Translation Rotation around origin . Rotation about the object itself (away from the origin) Reflect the object over x-axis or y-axis or both Reflect the object over a line (i.e. line y =-x) ShearingStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started