Assume the triangle’s vertices are wound in the order A, B, C

Form a normal to the triangle N = (B – A) x (C – A)

Now you can detect whether your triangle is clockwise or counter-clockwise by the sign of the dot product between this normal and the ray direction

In a left-handed coordinate system:

- Negative = Clockwise from ray’s point of view
- Positive = Counter-clockwise from ray’s point of view

In a right-handed coordinate system, it’s the opposite:

- Negative = Counter-clockwise from ray’s point of view
- Positive = Clockwise from ray’s point of view