How can I get the normal vector for a plane from a set of vertices?

I'm working on a HLSL / C++ little project to going over my graphics work, and I am unsure how I am to get a facing vector from a vertex polygon. I can't seem to find the formula.

The positions are P1, P2,P3

Let's call them class VertexPoint with P1.x, P1.y, P1.z for example?

• closely related question: gamedev.stackexchange.com/questions/11520/… Jun 26 '17 at 15:34
• Just for correctness, the label in the picture and question title should be "normal vector" instead of "normalized vector". The normal vector itself can of course be normalized (its length being the unity), but it doesn't need to, and the cross product won't produce a normalized vector by default. Jun 26 '17 at 18:57
• Googling "normal vector triangle", which is the obvious thing to Google, gives zillions of hits. 1, 2, 3, 4, 5, 6, ... Jun 27 '17 at 8:51
• ... 7, 8, 9, 10, 11, 12, 13, ... Jun 27 '17 at 8:58
• ... 14, 15, 16, 17 ... Every one of these (and doubtless countless others) answers the question—and some actually even have the desired C++/HLSL code. Seriously. This question has been so beaten to death, calling it "duplicate" is inadequate. "I can't seem to find the formula" my arse—you didn't try. Jun 27 '17 at 9:03

You could easily find the normal by calculating two vectors, V1 = P2-P1, and V2 = P3-P1, and then find the cross product N = V1 x V2. Then you normalize N. Depending on the ordering of the vertices (clockwise or counterclockwise) you will get a normal facing front or back.

You also need to make sure that three three points aren't aligned, if they are you have to pick another point.