The function that maps two coordinates into a node index is similar to Cantor pairing function (in the linked page, indices start from 0). See section "Inverting the Cantor pairing function".
Hi,
If I have a triangle like this:
1 2 4 7 11 16
3 5 8 12 17
6 9 13
10 14
15
... which goes on to contain numbers (although I don't think the size is relavent).
Notice the way it's ordered. The numbers can be considered as the ordinal index of a node of the triangle. The numbers are ordered going diagonally from top right to bottom left, and creating a new diagonal line which is longer as you go right.
The problem is, given a node with ordinal index , how can I find what the and coordinate is of ? Is there a formula?
For example:
get_x_index(13) = 2
get_y_index(13) = 2
get_x_index(17) = 4
get_y_index(17) = 1
Does anyone know how to do this?
Thanks.
The function that maps two coordinates into a node index is similar to Cantor pairing function (in the linked page, indices start from 0). See section "Inverting the Cantor pairing function".
ok thanks, that worked, but now given the triangle has n numbers where n is the amount of numbers in the triangle, how can I find the width and height of the triangle?
In the example in the beginning post, the width would be 6 and the height would be 5.