将三维共面点的列表排序为顺时针或逆时针 [英] Sorting a List of 3d coplanar points to be clockwise or counterclockwise

查看:590
本文介绍了将三维共面点的列表排序为顺时针或逆时针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个3D点列表。我知道他们都是共面的。我有我想要分类的中心,以及点和中心所在平面的法线。我怎样才能测试一点是否正确(或左)另一点?



我知道如何在2D中做到这一点。 按顺时针排序点?解释如何比较2d点。所以我认为我需要以某种方式将所有的点和中心转化为局部二维平面坐标。我怎样才能做到这一点?这是解决这个问题的最有效方法吗?

  //来自链接:
// a和b是points
// center是确定订单的中心
// int num =(ax-center.x)*(by-center.y) - (bx - center.x)*( ay - center.y);
//如果num = 0那么它们在同一行上
//如果num <0或num> 0则a在b

我将如何适应这种情况来处理3d共面点?

解决方案

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



您有中心 C 和正常 ñ的。要确定点b 是从点 A 的顺时针还是逆时针,计算点( n ),交叉( A C ))。如果结果是肯定的, B 是从 A 逆时针方向;如果是负值, B 是从 A 顺时针转动。

I have a list of 3D points. I know they are all coplanar. I have the center that I want to sort them around and the normal to the plane on which the points and the center lie. How can I test if one point is right (or left) of another point?

I understand how to do it in 2D. Sort points in clockwise order? explains how to compare 2d points. So I think I need to somehow covert all the points and the center to local 2d plane coordinates. How can I do that? Is it the most efficient way to solve this problem?

//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

How would I adapt this to handle 3d coplanar points?

解决方案

There's no need to convert everything to 2D.

You have the center C and the normal n. To determine whether point B is clockwise or counterclockwise from point A, calculate dot(n, cross(A-C, B-C)). If the result is positive, B is counterclockwise from A; if it's negative, B is clockwise from A.

这篇关于将三维共面点的列表排序为顺时针或逆时针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆