Fixed the function to calculate local position

checked with values - [ (3,5), (1,2), (4,7) ], [ (3,5), (1,2), (2,3) ],
[ (3,5), (1,2), (2,4) ] and works fine.