Avoiding collisions is a crucial ability for unmanned vehicles. In this paper, we present the constant avoidance angle algorithm, a reactive method for collision avoidance. It can be used to avoid both static and moving obstacles by making the vehicle keep an avoidance angle between itself and the obstacle edge. Unlike many other algorithms, it requires neither knowledge of the complete obstacle shape, nor that the vehicle follows a desired speed trajectory. Rather, safe vehicle headings are provided at the current vehicle speed. Thus, the speed can be used as an input to the algorithm, which provides flexibility and makes the approach suitable for a wide range of vehicles, including vehicles with a limited speed envelope or high acceleration cost. We demonstrate this by applying the algorithm to a marine vehicle described by a full kinematic and dynamic model in three degrees of freedom. We specifically consider vehicles with underactuated sway dynamics, where the vehicle velocity contains a component which cannot be directly controlled. Such dynamics can be highly detrimental to the performance of collision avoidance algorithms, and need to be included in the design and analysis of control systems for such vehicles. In this paper, we compensate for the underactuation by including these dynamics in the underlying analysis and control design. We provide a mathematical analysis of sparse obstacle scenarios, where we derive conditions under which safe avoidance is guaranteed, even for underactuated vehicles. We furthermore show how the modular nature of the algorithm enables it to be combined both with a target reaching and a path following guidance law. Finally, we validate the results both through numerical simulations, and through fullscale experiments aboard the R/V Gunnerus.