directed distance formula