drawpgram.py

Created by ews31415

Created on February 15, 2026

815 Bytes

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()

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.