-3

The idea is expressed by my picture.

enter image description here

For example: I will divide square 1 into triangle 1 and 2. So the coordinate of triangle 1 is (0, 1); (0, 0); (1, 0;) and the triangle 2 is (0, 1); (1, 0); (1, 1). Similarly to the rest of the squares.

Which algorithm i have to use in order to calculate the rest coordinates of all triangles.

Sangram Badi
  • 4,054
  • 9
  • 45
  • 78

1 Answers1

2

Just shift coordinates by (column, row). If you number triangles in linear manner, then for k-th triangle (with Wdt squares in row):

C = ((k - 1) / 2) mod Wdt   //integer modulo
R = (k - 1) / (2 * Wdt)  //integer division
if Odd(k)
    coords = (C, R + 1); (C, R); (C + 1, R)
else
    coords = (C, R + 1); (C + 1, R); (C + 1, R + 1)
MBo
  • 77,366
  • 5
  • 53
  • 86