Thread: How to find coordinate of node in triangle?

1. How to find coordinate of node in triangle?

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 $\displaystyle$n$$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 \displaystyle q$$, how can I find what the $\displaystyle$x$$and \displaystyle y$$ coordinate is of $\displaystyle$q? 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.

2. Re: How to find coordinate of node in triangle?

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".

3. Re: How to find coordinate of node in triangle?

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.

4. Re: How to find coordinate of node in triangle?

Originally Posted by Sneaky
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.
If you find the x and y coordinates of n, then I think that one of the dimensions of the triangle is x + y and the other one is either x + y or x + y - 1 depending on whether x (or maybe y) is 0.