From http://dominoc925.blogspot.in/2012/02/c-code-snippet-to-determine-if-point-is.html