How is determined the shape of the wings of an airplane? My understanding of the reason why a plane fly is summarized by the following figure: because the upper part of the wing is curved, the air above the wing has to flow faster than the wing below. This induces a force that lift the wing. 

My question is: 


*

*How is the exact shape of the wing determined? 

*What is the "optimal" curve for a wing? By "optimal", I mean the best lift. 

*How would the answer (shape of the wing) differ if we were looking for optimization of other parameters like stability.
PS: I am definitely not a physicist. If the question is too naive, please help to improve it. 
 A: A modern airfoil is designed on the basis of the desired pressure distribution over the chord length of both sides. In some cases, only a single angle of attack is relevant while in others the airfoil must be a compromise of the pressure distributions over a range of angles and flap deflections.
Two parameters can be used to tailor the desired pressure distributions:


*

*Relative thickness: Any body needs to displace air when it travels through it. This displacement causes supervelocities on both sides and extra drag (called wave drag) at supersonic speed. For better structural efficiency, a thicker airfoil is better, while a supersonic wing needs to be as thin as practical. Typical cases range from 22% at the root of WWII bombers over 13% for a modern airliner root all the way down to the 4% of a supersonic delta wing.

*Local camber: Positive local camber spreads the pressures on the lower and the upper side of an airfoil apart, such that is shows higher pressure on the lower and lower pressure on the upper side. This pressure difference is the source of lift.
Now it might seem that we ideally create a lot of suction on the upper surface while maximizing the pressure on the bottom surface, and that is indeed what an airliner wing with flaps extended for landing tries to do, but a few limitations exist.


*

*Pressure recovery: Once the flow leaves the airfoil at the trailing edge, its pressure should have returned to its ambient value. A big suction area on the rear-facing part of the airfoil will cause drag, so the area of low pressure should extend only over the forward and mid part of the chord length. The pressure gradient cannot be too steep in order to avoid flow separation. Separation makes further pressure recovery impossible and is very drag-intensive. The maximum pressure gradient at the desired maximum operating angle of attack therefore limits the minimum pressure over the forward part of the airfoil.

*Maximum local Mach number: Lower pressure means higher speed (the total energy of the flow is constant, and pressure is equivalent to potential energy), and since the flow behaves differently once it crosses into the supersonic realm, the minimum pressure can also be limited by the maximum local Mach number where recompression is still possible without causing a drag-intensive shock.

*Positive wing thickness: Sometimes reaching the theoretical optimum is prevented by the fact that the upper side of the airfoil must be above the lower side contour. 
Please follow the links if you want to know more - here I could only scratch the surface.
A: There are lots of answers on this site regarding "how is lift produced" etc. but this post asks about the determination of a typical wing profile, so it might be appropriate to follow through on that aspect.


*

*Determine the chord (length from wing leading edge to the trailing edge).

*Decide on your camber line, for a flat bottom surface wing, this is the shape of the curved upper surface. As in the comments above this parameter is determined by the use to which the aircraft is to be put and may involve camber on the lower wing surface.  In general, the faster the speed of your aircraft, the less camber thickness you need.
The first picture shows a Sopwith Camel c. 1915  with thick cambered wings and the  bottom image is of an almost camberless winged F105 60 years later. 


From here on physics is replaced by engineering, and a good source for basic principles is NASA Aircraft Design, from which my few comments are taken.
