mathutils implemented based on Dan's codes, and sort tested.