15 lines
614 B
JavaScript
15 lines
614 B
JavaScript
import {points} from "@turf/helpers";
|
|
import center from "@turf/center";
|
|
|
|
// [[-97.522259, 35.4691],
|
|
// [-97.502754, 35.463455],
|
|
// [-97.508269, 35.463245]]
|
|
export const pointSortClockwise = (coordinates) => {
|
|
const centerCoor = center(points(coordinates)).geometry.coordinates;
|
|
return coordinates.sort((a, b) => {
|
|
// 转换为以 centerCoor 为原点的坐标
|
|
const point_a = [a[0] - centerCoor[0], a[1] - centerCoor[1]]
|
|
const point_b = [b[0] - centerCoor[0], b[1] - centerCoor[1]]
|
|
return Math.atan2(...point_b.reverse()) - Math.atan2(...point_a.reverse())
|
|
})
|
|
} |