Any algorithm which involves sorting the points will fail for concave terrain, for example, consider the result you will obtain for the following two polylines when sorting by x-coordinate:
(entmake
'(
(0 . "LWPOLYLINE")
(100 . "AcDbEntity")
(100 . "AcDbPolyline")
(90 . 10)
(70 . 0)
(10 0.0 0.0)
(10 2.5 0.0)
(10 1.5 0.5)
(10 1.0 1.5)
(10 1.5 2.5)
(10 2.5 3.0)
(10 3.5 2.5)
(10 4.0 1.5)
(10 3.5 0.5)
(10 5.5 0.5)
)
)
(entmake
'(
(0 . "LWPOLYLINE")
(100 . "AcDbEntity")
(100 . "AcDbPolyline")
(90 . 4)
(70 . 0)
(10 0.0 0.5)
(10 2.5 0.5)
(10 3.5 1.0)
(10 5.5 1.0)
)
)
The correct result would be:
(entmake
'(
(0 . "LWPOLYLINE")
(100 . "AcDbEntity")
(100 . "AcDbPolyline")
(90 . 9)
(70 . 0)
(43 . 0.1)
(10 0.0 0.5)
(10 1.5 0.5)
(10 1.0 1.5)
(10 1.5 2.5)
(10 2.5 3.0)
(10 3.5 2.5)
(10 4.0 1.5)
(10 3.75 1.0)
(10 5.5 1.0)
)
)
But this cannot be achieved when sorting by either coordinate.