Skip to content

Instantly share code, notes, and snippets.

@ivankeller
Last active February 14, 2018 15:44
Show Gist options
  • Save ivankeller/4533a0ce4a2a97f66b9928e129b8bcea to your computer and use it in GitHub Desktop.
Save ivankeller/4533a0ce4a2a97f66b9928e129b8bcea to your computer and use it in GitHub Desktop.
Function that tests if a point belongs to a interval modulo (i.e. an arc of circle)
def belongs_to(t, a, b):
"""Return True if t belongs to real number interval [a, b], False otherwise."""
return t >= a and t <= b
def is_in_arc(t, a, b, m=365):
"""Return True if t is in the interval [a, b] modulo m, False otherwise"""
t, a, b = [x % m for x in (t, a, b)] # convert all the values to their values modulo m
if a < b:
return belongs_to(t, a, b)
else:
return not belongs_to(t, b, a)
@ivankeller
Copy link
Author

Useful for testing if a day-of-year is on a given day-of-year interval

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment