begin with task 3, implemented nearest and farthest intersection