works for 3 points