I would like to create a 2D right triangle grid for a game I am working on. Currently I am creating creating a 2D square grid, and each square contains 2 triangles.

I am wondering, is there a way to create and manage a right-triangle grid without having to contain 2 triangles in each square?


At first I thought you wanted to switch to equilateral triangles like below

Courtesy wikipedia.

Then you can index into this grid in the exact same way as a rectangular grid.

The top left triangle will be (0,0), and the one to the right of it will be (1,0) then to the right of that will be (2,0), etc.

The row below is (1, j).

However, I see now that you question is about right triangles.

That is just as easy, because two right triangles form a rectangle. So your coordinates will clearly still be rectangular, the same as above.

If you have a 2D array storing your grid of triangles, you can just index directly into any triangle using a rectangular coordinate system (i.e., pretend that you just have a grid of squares).

Right triangles in a grid.

So you'll have a 2D array that stores one triangle each. array[0,0] stores nothing, to make the coordinate system simpler.

There are multiple ways to index into these triangles, so I've just chosen the coordinate system that I think is easiest.

This corresponds to a rectangular coordinate system that you're used to pretty closely. If it's still not clear, just ask me to elaborate.

  • \$\begingroup\$ +1 For illustrations. You explained the idea well, but an ellaboration is still welcome :) \$\endgroup\$ Jun 4 '11 at 20:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.