开发者

Python Find distance between two coordinates

开发者 https://www.devze.com 2023-03-26 05:26 出处:网络
I\'m working with a range of 0 to 255. My data would be a set of numbers within this range. Except I need the difference between

I'm working with a range of 0 to 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 p开发者_如何学Cole.

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? i.e. 255 becomes 255 - 254 if it is being compared against [1 - 127.4]


def diff256(a, b):
  return min((a - b) % 256, (b - a) % 256)
0

精彩评论

暂无评论...
验证码 换一张
取 消