将3d共面点列表排序为顺时针或逆时针

AAB*_*AAB 10 math geometry linear-algebra

我有一个3D点列表.我知道他们都是共面的.我有一个中心,我想要对它们进行排序,以及点和中心所在平面的法线.如何测试一个点是否正确(或左)另一个点?

我理解如何在2D中完成它.按顺时针顺序排序点?解释了如何比较2d点.所以我想我需要以某种方式将所有点和中心转换为局部2d平面坐标.我怎样才能做到这一点?这是解决这个问题最有效的方法吗?

//from link:
// a and b are points
//center is the center around which to determine order
//int num = (a.x-center.x) * (b.y-center.y) - (b.x - center.x) * (a.y - center.y);
//if num=0 then they're on the same line
//if num <0 or num>0 then a is to the left or right of b
Run Code Online (Sandbox Code Playgroud)

我如何调整它以处理3d共面点?

Bet*_*eta 18

没有必要将所有内容转换为2D.

你有中心C和正常的n.要确定点B是从A点顺时针还是逆时针,计算点(n,交叉(A - C,B - C)).如果结果为正,则BA逆时针方向; 如果是负数,则BA开始顺时针方向.