[英]Python Find distance between two coordinates
I'm working with a range of 0 to 255. 我正在使用0到255的范围。
My data would be a set of numbers within this range. 我的数据是这个范围内的一组数字。
Except I need the difference between 除了我需要的区别
255 & 0 = 1
254 & 5 = 7
So in a sense this range is a circular set, and 255 and 0 are the pole. 所以从某种意义上说,这个范围是一个圆形集合,255和0是极点。
Is there some function / easy way to do this? 有没有一些功能/简单的方法来做到这一点? Or do I need to take the second half of the range and assign it some value to be calculated against?
或者我是否需要采用范围的后半部分并为其分配一些值来计算? ie 255 becomes 255 - 254 if it is being compared against [1 - 127.4]
即如果与[1 - 127.4]进行比较,则255变为255 - 254
def diff256(a, b):
return min((a - b) % 256, (b - a) % 256)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.