已知环形区域的中心(如椭圆中心,圆心),求轮廓的起止角度
代码实现
在线测试:https://onlinegdb.com/gwszKcq59
Python版本
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 
 | import os
 def get_angle_range(angles,acc=10):
 """
 获取角度范围
 """
 angles += [i+360 for i in angles]
 angles = sorted(angles)
 # 初始化起始角度
 res = [angles[0]]
 for i in range(len(angles)-1):
 
 if angles[i+1] - angles[i] >acc:
 res.append(angles[i])
 res.append(angles[i+1])
 assert len(res)==5 or len(res)==3,print("识别有错误")
 if len(res)==5:
 return res[2:4]
 else:
 return res[:2]
 
 if __name__=="__main__":
 case1 = list(range(0, 90,5)) + list(range(270, 360,5)) # 0-90 270-360 连续的角度:270-450
 print(get_angle_range(case1,acc=10))
 
 case2 = list(range(90, 270,5)) # 90-270 连续的角度:90-270
 print(get_angle_range(case2,acc=10))
 
 
 | 
C++版本: