Saturday, June 13, 2026

Numworks (Python): Parallelograms Described by Vectors

Numworks (Python): Parallelograms Described by Vectors



Introduction



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]). Let the two vectors be labeled as [x1, y1] and [x2, y2].



This script also 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).







Then the perimeter of the parallelogram is calculated as:

perimeter = 2 * (norm([x1, y1] + norm[x2, y2]) = 2 * (√(x1 + y1) * √(x2, y2))



And the area is calculated as:

area = abs(det([[x1, y1] [x2, y2]])) = abs(x1 * y2 – x2 * y1)





Numworks Script: drawpgram.py

Modules used: Math, PyPlot



Script page: https://my.numworks.com/python/ews31415/drawpgram



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



Notes:

1. I use eval(input( “prompt” )) and importing the Math module to allow for expressions to be entered, such as expressions involving pi (π). If I use float(input( “prompt” )) instead, only numbers would be allowed.

2. For the purposes of display, the results are rounded off to six decimal places ({0:.6f}) and displayed in a line. The full precision results of area and perimeter are stored in the variables area and perim, respectively.



Examples



Example 1: [2, 4], [5, 2]



Example 2: [-3, 1], [5, 3]



Example 3: [-6, 0], [0, -4]



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



Eddie


All original content copyright, © 2011-2026. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.

Numworks (Python): Parallelograms Described by Vectors

Numworks (Python): Parallelograms Described by Vectors Introduction The script drawpgram.py draws a parallelogram constructed by ...