Can someone provide me a general algorithm to compute the angle of attack of an airfoil, and some theory along with it?
The angle of attack is the angle between the wing and the direction of flight. The direction of flight is opposite to the airflow, so the angle of attack is also the angle between the wing and the relative wind.
For a more refined definition (thanks @Peter Kämpf): The flight path direction (the velocity vector in the language of aerodynamicists) should be expressed relative to the air mass, not to the ground (as measured by an inertial system), but that's beyond the topic.
How to compute it? Well, it's like airspeed, we don't. It's just measured using a small windvane:
A380 angle of attack sensor (combined with a Pitot-static), source
In the image above, the black angle of attack sensor is combined with a classic Pitot-static which measures airspeed. On airliners, there are usually several AOA sensors. The one in the picture is located on the FO side, air comes from the right side.
Another simple AOA sensor at the bottom, Captain side:
Source (original source not found)
There is a specific AOA sensor found on GA aircraft, to trigger an alarm when approaching the critical angle of attack: The stall sensor:
This strip located at the wing leading edge has two positions and rock abruptly before the critical angle of attack is reached. It triggers an alarm in the cockpit, so that the pilot can reduce the angle of attack.
A final note: The AOA wasn't displayed to the crew in the cockpit, only the pitch angle was. Newer aircraft now display both. I think it was a recommendation of the BEA after AF447 accident, were the crew couldn't figure out the AOA they were at after a Pitot-static froze.
First and foremost, we need to define what Angle of Attack is.
The angle of attack in fluid dynamics is the angle between a reference line on a body and a vector which represents the flow of fluid over the body.
For aircraft, we are generally talking about the wing's angle of attack to produce lift. To do this we substitute a chord line for the body, and the wind direction for the vector. However, the AOA is constantly changing during flight, because of this the most common way of finding your angle of attack is to measure it. In-flight this is done by using an Angle of Attack indicator shown below ]2
The method used to measure the angle of attack is described in this article
The AOA tube is constructed with two tiny machined holes to create differential pressure sources. One hole is bore-sighted at the front of the AOA tube along the longitudinal axis, while the second, located at the bottom of the AOA probe, is pointed downward at a 45-degree angle to act as a reference source. From here the data is sent to a computer which determines the current AOA and adjusts the indicator appropriately.
AOA can also be roughly determined in-flight by taking the difference of the aircraft's angle of incidence and flight-path vector; however in rough weather and turbulence this method becomes inaccurate.
For computation purposes, the AOA is calculated by taking the absolute value of the result you get from the difference between the direction of wind and direction of the chord of the wing:
AOA = |wind-chord|
With that said, if you are going to try to convert this into a coefficient of lift, it's important to remember that the lift of a finite wing at a certain AOA is less than the lift of an infinite wing at the same AOA. For that, I will leave you this link which may be helpful.