开发者

Sorting points in trigonometric order in 3d space

开发者 https://www.devze.com 2023-03-27 06:34 出处:网络
I have three points in 3d space A,B,C. The points are not collinear. I wish to sort the points in such a way that if I traverse them I would traverse the triangle A开发者_如何学CBC in trigonometric(co

I have three points in 3d space A,B,C. The points are not collinear. I wish to sort the points in such a way that if I traverse them I would traverse the triangle A开发者_如何学CBC in trigonometric(counterclockwise) order.


You have to define which side of the triangle you are looking at. The ordering that is counter-clockwise (CCW) will be clockwise (CW) when viewed from the other side of the triangle.

You can pick any order ABC and then compute the cross product (A-C)x(B-C) which will give you a vector normal to the plane of the triangle. The direction it points (up or down) will depend on the ordering you've chosen. If its the wrong order you may reverse your ordering or swap two points.

The key is to figure out which side you are going to view it from before talking about direction.


Since you have only 6 possible orderings, I would go for the brute force approach: for each ordering, check if it satisfies your constraint, and if it does, chose it.

0

精彩评论

暂无评论...
验证码 换一张
取 消