1

How to find the orientation of three vertices A, B and C of a plane in 3D are in clockwise, anticlockwise or collinear? I find this below link in 2D

http://www.geeksforgeeks.org/orientation-3-ordered-points/

I have tried in 3D, but I am not sure about this. dot(n, cross(A-C, B-C)) where n is normal to a plane.

If the result is positive, B is counterclockwise from A; if it's negative, B is clockwise from A. Any help would be much appreciated.

  • 1
    Isn't the result dependant on definition of "normal vector $n$ to a plane $A,B,C$" ? – z100 Aug 08 '17 at 15:21
  • 2
    in 3D if you watch from one side they are clockwise, from the other side counterclockwise. – wonko Aug 08 '17 at 15:22
  • 1
    The formula you've used -- with the dot and cross product -- is correct. Try it with $A = (0,0,0), B = (1, 0, 0), C = (0, 1, 0)$, and normal vector $n = (0,0,1)$ to see that the postive result does indeed correspond to "counterclockwise as viewed from the endpoint of $n$, looking toward the basepoint of $n$." – John Hughes Aug 08 '17 at 16:05

1 Answers1

2

Let's say your three points are $\vec{p}_1 = ( x_1 , y_1 , z_1 )$, $\vec{p}_2 = ( x_2 , y_2 , z_2 )$, and $\vec{p}_3 = ( x_3 , y_3 , z_3 )$.

Let $$\vec{n} = \left ( \vec{p}_2 - \vec{p}_1 \right ) \times \left ( \vec{p}_3 - \vec{p}_1 \right )$$ i.e. $$\begin{cases} x_n = (y_2 - y_1) (z_3 - z_1) - (z_2 - z_1) (y_3 - y_1) \\ y_n = (z_2 - z_1) (x_3 - x_1) - (x_2 - x_1) (z_3 - z_1) \\ z_n = (x_2 - x_1) (y_3 - y_1) - (y_2 - y_1) (x_3 - x_1) \end{cases} $$ If the three points are collinear, then $\vec{n} = ( 0 , 0 , 0 ) = 0$. Otherwise, the three points are on a plane, with $\vec{n}$ being normal (perpendicular) to the plane.

As mentioned in a comment, if we look at the triangle from the side the normal vector $\vec{n}$ points to, the points are in counterclockwise order; but, if we look at the triangle from the other side, they are in clockwise order.

If we know that the three points are on a plane with normal vector $\vec{k}$, then $$\begin{cases} \vec{k} \cdot \vec{n} = \vec{k} \cdot \left ( \left ( \vec{p}_2 - \vec{p}_1 \right ) \times \left ( \vec{p}_3 - \vec{p}_1 \right ) \right ) \gt 0, & \text{ counterclockwise } \\ \vec{k} \cdot \vec{n} = \vec{k} \cdot \left ( \left ( \vec{p}_2 - \vec{p}_1 \right ) \times \left ( \vec{p}_3 - \vec{p}_1 \right ) \right ) \lt 0, & \text{ clockwise } \\ \vec{k} \cdot \vec{n} = \vec{k} \cdot \left ( \left ( \vec{p}_2 - \vec{p}_1 \right ) \times \left ( \vec{p}_3 - \vec{p}_1 \right ) \right ) = 0, & \text{ oops } \end{cases}$$

The "oops" case covers several possible situations. For example, if the three points are collinear, then $\vec{n} = 0$. Or, if the three points are on a plane parallel to $\vec{k}$, the result is zero also.