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:

Triangle

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:

  1. Declare the Triangle structure in Geometry3D.h:
    typedef struct Triangle { union ...

Get Game Physics Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.