2D Vector

python, pyclass

I'm using this python class to do calculation in a 2D world, I've added some handy functions such as distance, dot product, angle, perpendicular vector, intersection of two lines (see below), circumcircle of 3 points. Unlike default python array, you can + - * / the vectors ;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
vector_1 = Vector2(0, 3)
vector_2 = Vector2(4, 2)
addition = vector_1 + vector_2
division = vector_1 / vector_2
# and so on..
      
      
# Two lines intersection example ;
pA, pB = Vector2(1,2), Vector2(4,8)
pC, pD = Vector2(8,1), Vector2(3,5)
line_AB = pA.line(pB)
line_CD = pC.line(pD)

pI = Vector2.intersect(line_AB, line_CD) # returns a point

If you have any questions... =)