好久没碰2d,3d的东西了,翻出个向量类,正好用于道路抽稀时根据转角来剔除多余的中间节点
1 import os,os.path,sys,time,copy,shutil,math
2 from gameobjects.vector2 import Vector2
3
4 a=(2,6)
5 b= (1,2)
6 c=(5,2.48)
7
8 #计算ba与bc夹角 Labc
9 def pp_distance(p1,p2):
10 return math.sqrt( (p1[0]-p2[0])**2+ (p1[1]-p2[1])**2)
11
12 ba= Vector2.from_points(b,a)
13 bc = Vector2.from_points(b,c)
14 #点乘计算夹角
15 dot = (ba[0]*bc[0]+ba[1]*bc[1] )
16 x = dot/ (ba.get_magnitude()*bc.get_magnitude() )
17 angle = (math.acos(x) / math.pi) * 180
18 print angle
19