Created
April 11, 2012 11:39
-
-
Save PhDP/2358809 to your computer and use it in GitHub Desktop.
Convert a linear index to X-Y coordinates from an upper triangular matrix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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