How can I find the area of a 3D triangle?

Hi there - can someone help me?

I’m writing a small 3D viewer which, in addition to the triangle mesh of a loaded model, also draws the facet and vertex normals as little lines. Eventually, you will be able to edit the vertex normals to tweak the shading in low-poly models.

The lengths of the facet normals should be proportional to the ‘size’ of the actual triangle - ie. not it’s 2D projected size. So I need a way to (quickly) calculate the area of the triangle.

Now I know who to calculate the area of a 2D triangle: (H x w)/2. But how can I calculate the area of a triangle defined by three 3D points? It’s still a planar triangle, but in 3D space.

Ideally, this would just be a float that I would multiply the vector normal with

you should have structures like

typedef struct { 
 int   id;
 float x, y, z; } Node;

typedef struct {
 int id;
 Node *N[3]; } Tria; 

now for each tria:

  1. calculate vectors e1 and e2 (which can be of
    type Node, too) from N[0]->N[1] and N[0]->N[2] :

e1.x = N[1]->x - N[0]->x;
e1.y = N[1]->y - N[0]->y;
e1.z = N[1]->z - N[0]->z;

e2.x = N[2]->x - N[0]->x;
e2.y = N[2]->y - N[0]->y;
e2.z = N[2]->z - N[0]->z;

  1. calculate e3 = e1 x e2 (cross product) :

e3.x = e1.ye2.z - e1.ze2.y;
e3.y = e1.ze2.x - e1.xe2.z;
e3.z = e1.xe2.y - e1.ye2.x;

  1. the tria area is the half length of the
    normal vector:

A = 0.5sqrt(e3.xe3.x + e3.ye3.y + e3.ze3.z);

good luck!

Oh ok. Thanks a lot!!!