distance formula simulation