Triangle
Triangles are one of the most important primitive shapes for 3D graphics. A triangle can be represented by three non linear points. Triangles are special because they are co-planar. This means that the three points of a triangle always lie on the same plane:

Getting ready
We are going to implement a triangle that is defined by three points. To make this structure more convenient to use, we can declare an anonymous union. This union will let us access the members of the Triangle
struct
in different ways.
How to do it
Follow these steps to implement a 3D triangle:
Declare the
Triangle
structure inGeometry3D.h
:typedef struct Triangle { union {
The points of a triangle should be accessible as three separate points:
a
,b
andc
:struct { Point a; Point b; Point c; };
One of the alternate methods to access the points of a triangle is as an array of points:
Point points[3];
The final way of accessing the points of a triangle is as a linear...