Skip to content

Instantly share code, notes, and snippets.

@PhDP PhDP/linear-upper.py
Created Apr 11, 2012

Embed
What would you like to do?
Convert a linear index to X-Y coordinates from an upper triangular matrix
def getX(i):
return int(-0.5 + 0.5 * sqrt(1 + 8 * (i - 1))) + 2
def getY(i):
return getX(i) * (3 - getX(i)) / 2 + i - 1
def getXY(i):
return (getX(i + 1) - 1, getY(i + 1) - 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.