Search code examples
pythonopenglgeometryalgebra

Order coplanar points for drawing them


I have an algorithm which generates from three to six points of intersection between a plane and the edges of a cube which contains that plane. For drawing the plane (which gets drawn a polygon) OpenGL needs the vertex to be ordered as in the following picture:

enter image description here

If the vertex are unordered, this result may be drawn: enter image description here

Edit: I found this question but I don't know how to code it in Python and that's not exactly what I need


Solution

  • If points were built as intersections between a plane and the edges of a cube, then they form convex polygon.

    To properly order vertices of this polygon, make projection onto some plane - or onto section plane, or onto one of OXY, OXZ, OYZ planes - just choose one not normal to section plane and make corresponding component zero.

    Then choose the leftmost point in that plane as base and sort other points by polar angle relative to base.