The operation of Unmanned Aerial Vehicles (UAVs) in civil airspace is restricted by the aviation authorities, which require full compliance with regulations that apply for manned aircraft. This paper proposes control algorithms for a collision avoidance system that can be used as an advisory system or a guidance system for UAVs that are flying in civil airspace under visual flight rules. A decision-making system for collision avoidance is developed based on the rules of the air. The proposed architecture of the decision-making system is engineered to be implementable in both manned aircraft and UAVs to perform different tasks ranging from collision detection to a safe avoidance manoeuvre initiation. Avoidance manoeuvres that are compliant with the rules of the air are proposed based on pilot suggestions for a subset of possible collision scenarios. The proposed avoidance manoeuvres are parameterized using a geometric approach. An optimal collision avoidance algorithm is developed for real-time local trajectory planning. Essentially, a finite-horizon optimal control problem is periodically solved in real-time hence updating the aircraft trajectory to avoid obstacles and track a predefined trajectory. The optimal control problem is formulated in output space, and parameterized by using B-splines. Then the optimal designed outputs are mapped into control inputs of the system by using the inverse dynamics of a fixed wing aircraft.