writing circle direction detection algorithm