import math


def get_euler_angles(rotation_matrix, radians=True):
  """Returns the euler angles from a rotation matrix.

  Euler angles are, in order, yaw (heading), pitch (elevation) and roll.
  Angles are returned in degrees unless specified otherwise by setting the
  parameter radians to True.

  Args:
    rotation_matrix: 3x3 rotation matrix.
    radians: Whether to output values in radians or in degrees.

  Returns:
    Triplet of angles yaw (heading), pitch (elevation) and roll.
  """
  pi = math.pi
  yaw = -math.atan2(rotation_matrix[0][1], rotation_matrix[0][0]) % (2 * pi)
  pitch = -math.atan2(rotation_matrix[1][2], rotation_matrix[2][2]) % (2 * pi)
  roll = math.asin(rotation_matrix[0][2]) % (2 * pi)
  if not radians:
    yaw, pitch, roll = [math.degrees(angle) for angle in [yaw, pitch, roll]]
  return yaw, pitch, roll