The script drawpgram.py draws a parallelogram constructed by a pair of two-dimensional vectors. Both vectors original from the origin of the Cartesian plane ([0, 0]). Then the script calculates the area and perimeter of the constructed parallelogram consisting of the end points (0,0), (x1, y1), (x2, y2), and (x1+x2, y1+y2).
Source Margalit, Dan and Joseph Rabinoff. 2025. “Determinants and Volumes” Interactive Linear Algebra LibreTexts. Accessed February 8, 2026. https://math.libretexts.org/Bookshelves/Linear_Algebra/Interactive_Linear_Algebra_(Margalit_and_Rabinoff)/04%3A_Determinants/4.03%3A_Determinants_and_Volumes
# Draw a parallelogram with two vectors # Edward Shore, 2/15/2026 # Numworks # drawpgram.py from math import * from matplotlib.pyplot import * print("Draw a parallelogram with 2 vectors") x1=eval(input("x1? ")) y1=eval(input("y1? ")) x2=eval(input("x2? ")) y2=eval(input("y2? ")) # Area area=abs(x1*y2-x2*y1) # Perimeter perim=2*((x1**2+y1**2)**(1/2)+(x2**2+y2**2)**(1/2)) minx=min([x1,x2,x1+x2,0]) maxx=max([x1,x2,x1+x2,0]) miny=min([y1,y2,y1+y2,0]) maxy=max([y1,y2,y1+y2,0]) axis((minx-1,maxx+1,miny-1,maxy+5)) plot([0,x1],[0,y1],'blue') plot([0,x2],[0,y2],'purple') plot([x1,x1+x2],[y1,y1+y2],'purple') plot([x2,x1+x2],[y2,y1+y2],'blue') str1="area = {0:.6f}".format(area) text(minx-1,maxy+4.5,str1) str2="perim = {0:.6f}".format(perim) text((minx+maxx)/2,maxy+4.5,str2) show()