import math


def compute_pitch_angle(source_coordinates, target_coordinates, radians=True):
  """Computes pitch (elevation) angle given two xyz coordinates.

  Args:
    source_coordinates: Source triplet with xyz coordinates.
    target_coordinates: Target triplet with xyz coordinates.
    radians: Whether to output in radians or degrees.

  Returns:
    Pitch angle. 0 means neutral elevation, angles increase towards positive
    z coordinates. In radians, pi means looking at the ceiling and -pi means
    looking at the floor.
  """
  source_x, source_y, source_z = source_coordinates
  target_x, target_y, target_z = target_coordinates

  delta_x = target_x - source_x
  delta_y = target_y - source_y
  delta_z = target_z - source_z
  delta_xy = math.sqrt(delta_x**2 + delta_y**2)

  pitch = math.atan2(delta_z, delta_xy)

  if radians:
    return pitch
  return math.degrees(pitch)