P
P
pogoreli2021-06-04 14:20:19
3D
pogoreli, 2021-06-04 14:20:19

How to sort points counter-clockwise in 3D space by right-hand rule given their coordinates and normal?

I'm currently trying to write an algorithm in c# to open 3d models and fix broken files. I have 3 arrays of the same length - point coordinates, their normals, and triangles. Model files contain the following information:

facet normal nx ny nz
outer loop
vertex v1x v1y v1z
vertex v2x v2y v2z
vertex v3x v3y v3z
endloop
endfacet

This is a stl file, but it's just an example, because in other formats everything is very similar.

The normal is the same for all three points, so it's just duplicated 3 times.

By standard, these points must be in counter-clockwise order, but in practice, not all applications adhere to this rule.

If you count everything manually, then the normal is perpendicular to the plane of the triangle and goes out of it. Accordingly, you just need to draw a triangle, attach your right hand to it, pointing your thumb in the direction of the normal, and the remaining fingers will show the desired direction.
orientation-rule.gif
But in reality, there can be hundreds and thousands of such triangles. And how to convert the right hand rule into an algorithm, I do not understand.

Maybe someone has come across this, and can help make a mathematical model, or algorithm. I write this in c# if I need some specific features of the language, but I rather just need to understand the sequence of actions itself, so formulas or a pseudo language will help me a lot.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Ocelot, 2021-06-04
@pogoreli

We take two vectors: 1->2 and 1->3, we consider their vector product. If its direction coincides with the normal direction of the triangle, then the points are in the correct order. If not, swap points 2 and 3.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question