Game Designer & Developer


Game Dev

Diamond Angle

This will calculate the clockwise or anti-clockwise angle (depending on coordinate system chirality) of a vector in a range of 00 to 44 where each whole unit is equal to 90°90\degree.

One notable aspect of this method though is that it only calculates the positive angle, whereas a true trigonometric method would calculate the absolute minimum, giving negative angles instead of angles greater than 180°180\degree. This can actually be quite useful in some situations but it is important to remember this distinction.

The formula to find the diamond angle, sometimes called the taxi-cab angle, of a vector in hectogradians (1 hgrad = 100 grad) is as follows:

dia={0+y/(x+y)if y>=0 and x>=01x/(x+y)if y>=0 and x<02y/(xy)if y<0 and x<03+x/(xy)if y<0 and x>=0 dia = \begin{cases} 0+y/(x+y) &\text{if } y >= 0 &\text{ and } &x >= 0 \\ 1-x/(-x+y) &\text{if } y >= 0 &\text{ and } &x < 0 \\ 2-y/(-x-y) &\text{if } y < 0 &\text{ and } &x < 0 \\ 3+x/(x-y) &\text{if } y < 0 &\text{ and } &x >= 0 \end{cases}

Code

Example Python code

def diamond_angle(x, y):
  if y >= 0 and x >= 0:
    return y/(x+y)
  elif y >= 0 and x < 0:
    return 1-x/(-x+y)
  elif y < 0 and x < 0:
    return 2-y/(-x-y)
  elif y < 0 and x >= 0:
    return 3+x/(x-y)