本文整理汇总了Python中vector.Vector.angleBetween方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.angleBetween方法的具体用法?Python Vector.angleBetween怎么用?Python Vector.angleBetween使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vector.Vector
的用法示例。
在下文中一共展示了Vector.angleBetween方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_angle_between_with_zero_vector
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import angleBetween [as 别名]
def test_angle_between_with_zero_vector(self):
v1 = Vector([1,2,-1])
v2 = Vector([0,0,0])
with self.assertRaises(Exception) as context:
v1.angleBetween(v2)
self.assertTrue('Cannot calculate the angle between using a zero vector' in str(context.exception))
示例2: test_angle_between
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import angleBetween [as 别名]
def test_angle_between(self):
v1 = Vector([1,2,-1])
v2 = Vector([3,1,0])
self.assertEqual(v1.angleBetween(v2), 0.869122203007293)
self.assertEqual(v1.angleBetween(v2, degrees=True), 49.797034113430236)
示例3: estimateOrientations
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import angleBetween [as 别名]
def estimateOrientations(self, bucket_classifications, estimated_positions):
combinations = self.colorCombinations()
estimated_orientations = {}
# for c in combinations:
# estimated_orientations[c] = None, None
for key, center in estimated_positions.iteritems():
if center is None:
estimated_orientations[key] = None
continue
side_color, main_color = key
support_color = self.opposingColor(main_color)
support_orientation_vector = None
final_vector = None
if self.previous_orientations[key].full():
support_orientation_vector = self.previous_orientations[key].getLeft()
# bucket_index = self.findBucket(buckets, bucket_classifications, key, num_buckets)
# if bucket_index == -1:
# final_vector = support_orientation_vector
# self.updateOrientations(estimated_orientations, final_vector, key)
# continue
bucket_key = bucket_classifications[key]
if bucket_key is None:
final_vector = support_orientation_vector
self.updateOrientations(estimated_orientations, final_vector, key)
continue
for bucket_center, bucket_color in bucket_key:
if bucket_color == support_color:
support_orientation_vector = Vector.getDirectionVector( bucket_center, center, 1 )
support_orientation_vector.rotate(math.radians(215))
if support_orientation_vector is None:
final_vector = None
self.updateOrientations(estimated_orientations, final_vector, key)
continue
centers_main_color = [ x for (x, c) in bucket_key if c == main_color ]
centers_len = len(centers_main_color)
midpoints_main_color = []
for i in range(centers_len - 1):
for j in range(i+1, centers_len):
center_i = centers_main_color[i]
center_j = centers_main_color[j]
midpoints_main_color.append( meanPoint([center_i, center_j]) )
dvs_main_color = [ Vector.getDirectionVector(x, center, 10) for x in midpoints_main_color]
dvs_len = len(dvs_main_color)
if dvs_len < 2:
final_vector = support_orientation_vector
self.updateOrientations(estimated_orientations, final_vector, key)
continue
angle_min = 999999
vector_min = None
for v in dvs_main_color:
if support_orientation_vector.toPoint() == (0, 0) or v.toPoint() == (0,0):
self.updateOrientations(estimated_orientations, None, key)
continue
angle_tmp = abs(Vector.angleBetween(support_orientation_vector, v))
if angle_tmp < angle_min:
angle_min = angle_tmp
vector_min = v
angle_check = abs(Vector.angleBetween(vector_min, support_orientation_vector))
if angle_check < 20:
final_vector = vector_min
else:
final_vector = support_orientation_vector
self.updateOrientations(estimated_orientations, final_vector, key)
self.previous_orientations[key].insert(final_vector)
return estimated_orientations