Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Need to draw a triangle from A, B, and C. all of which are 2*1 matrices containing the x and y coordinates created using numpy
Need to draw a triangle from A, B, and C. all of which are 2*1 matrices containing the x and y coordinates created using numpy array function. Struggling to find a way to properly plot the triangle without the gap at the base.
pp.py Lo_p.py import numpy as np import matplotlib.pyplot as plt A = np.array( [[0], [0]]) B = np.array([[0], [1]]) C = np.array([[1], [0]]) s_x = float(input('Please enter scale factor in x direction: ')) s_y = float(input('Please enter scale factor in y direction: ')) scale_matrix = np.array([[s_x,0], [0,s_y]]) print (scale_matrix) r = float(input('Please enter angle of rotation in degrees: ')) r = r * (np. pi/180) rotation_matrix = np.array([[np.cos(r), -np.sin(r)], [np.sin(r), np.cos(r)]]) print (rotation_matrix) composite_matrix = rotation_matrix @ scale_matrix print(composite_matrix) Af = composite_matrix @ A Bf = composite_matrix @ B Cf = composite_matrix @ C print(Af, ' ', Bf, ' ',Cf) plt.axis('equal') plt.grid () plt.plot (A,B,C, color= 'b') plt.show() L [[0.5 0.] [[0.] 10 [0.]] 0.8 0.6 0.4 In [37]: | 0.2 Console 1/A X 0.0 [0. 1.5]] Please enter angle of rotation in degrees:30 [[ 0.8660254 -0.5 [ 0.5 [[ 0.4330127 [ 0.25 [[-0.75 [ 1.29903811]] [[0.4330127] [0.25 ]] -0.2 0.0 0.8660254]] -0.75 ] 1.29903811]] ] 0.2 0.4 0.6 0.8 10 Help Variable Explorer Plots Files IPython Console History Terminal 12
Step by Step Solution
★★★★★
3.32 Rating (143 Votes )
There are 3 Steps involved in it
Step: 1
To draw a triangle using NumPy arrays in Python without a gap at the base you can use the matpl...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