Sort half-edges around common vertex in 3d
If projecting them onto the plane of the vertex normal doesn't do the job, I'm not sure what would. There isn't any unambiguous way to do this in 3D. Imagine the new triangle that you are on there joining is perpendicular to the existing two triangles? What would you want the answer to be in that case?
I suppose you could try &quot;voting&quot; by dotting the new triangle's normal with each of the existing triangle's normals. A positive dot is a vote to keep the current orientation, a negative dot is a vote to flip it. Maybe weight the votes by the triangles' areas, or their angles at that vertex. Of course you'd have to decide how to break ties, and this might just give you similar problems to the plane of the common vertex normal.
This would make more sense if you were constructing a new triangle that shared an edge with one of the existing triangles. Then you could copy the orientation from the triangle that it was joined to. I'm not sure what kind of 3D modeling operation you're doing that produces this situation, but if there's any way you can accomplish it by building things in terms of common edges rather than common vertices, you'll probably have a much better time.