MissionPlanner.Grid.FindLineIntersection C# (CSharp) Method

FindLineIntersection() public static method

from http://stackoverflow.com/questions/1119451/how-to-tell-if-a-line-intersects-a-polygon-in-c
public static FindLineIntersection ( MissionPlanner.Utilities.utmpos start1, MissionPlanner.Utilities.utmpos end1, MissionPlanner.Utilities.utmpos start2, MissionPlanner.Utilities.utmpos end2 ) : MissionPlanner.Utilities.utmpos
start1 MissionPlanner.Utilities.utmpos
end1 MissionPlanner.Utilities.utmpos
start2 MissionPlanner.Utilities.utmpos
end2 MissionPlanner.Utilities.utmpos
return MissionPlanner.Utilities.utmpos
        public static utmpos FindLineIntersection(utmpos start1, utmpos end1, utmpos start2, utmpos end2)
        {
            double denom = ((end1.x - start1.x) * (end2.y - start2.y)) - ((end1.y - start1.y) * (end2.x - start2.x));
            //  AB & CD are parallel         
            if (denom == 0)
                return utmpos.Zero;
            double numer = ((start1.y - start2.y) * (end2.x - start2.x)) - ((start1.x - start2.x) * (end2.y - start2.y));
            double r = numer / denom;
            double numer2 = ((start1.y - start2.y) * (end1.x - start1.x)) - ((start1.x - start2.x) * (end1.y - start1.y));
            double s = numer2 / denom;
            if ((r < 0 || r > 1) || (s < 0 || s > 1))
                return utmpos.Zero;
            // Find intersection point      
            utmpos result = new utmpos();
            result.x = start1.x + (r * (end1.x - start1.x));
            result.y = start1.y + (r * (end1.y - start1.y));
            result.zone = start1.zone;
            return result;
        }