Introduction to Game Programming with C++ (Wordware Game Developers Library)

3.5 Polygons and Shapes

When lines meet and form complete boundaries, they make shapes with different numbers of sides. These shapes are called polygons. The polygon with the fewest number of sides is a triangle. It has three sides and three angles. A quadrilateral is bounded by four sides. There is no limit to the number of sides a polygon may have.

To summarize then, a polygon is a shape formed by the intersection of three or more lines that make a boundary. The points where the lines meet are called vertices; these are the vertices of the polygon. At these vertices, angles are formed. The lines themselves form the edges of the polygon.

3.5.1 Triangles

A triangle is the simplest polygon. It is made up of three sides and has three angles. Using a combination of triangles, every other polygon can be formed. For example, squares are made up of two adjacent triangles. The sum of angles in a triangle is equal to two right angles, and at least two angles in every triangle are acute. There are four types of triangles.

Figure 3.11: Reproduced from Wikipedia under the GNU license

Note 

When faced with a simple polygon that has any number of sides, you can determine how many triangles it is composed of by subtracting 2 from the number of sides. The result will be the number of triangles. For example, how many triangles are in a square? A square has four sides, so 4 − 2 = 2, which means two triangles.

3.5.2 Squares

A square is composed of two right triangles. We know the total angle sum in a triangle is two right angles, and therefore the total sum in a square must be twice this amount. A square has four equal sides and four right angles.

Figure 3.12

Категории