Calculating line direction