this function can calculate distance with two direction