In this chapter, we present two basic concepts required for constructing and rotating three-dimensional polygons. The first concept refers to the analytical equations to project points from a three-dimensional space onto a two-dimensional screen. The second concept refers to the equations to calculate the rotation of points in a three-dimensional space.

## 4.1 Projecting a Three-Dimensional Point Onto a Plane

Figure 4-1 depicts two three-dimensional points, *P* and *P*^{′}, with coordinates (*x*, *y*, *z*) and (*x*^{′}, *y*^{′}, *z*^{′}), respectively. Point *P*^{′}, the *projected point,* is obtained by projecting *P* on the computer’s screen by drawing a straight line from a fixed point *V* with coordinates (*V*_{X}, *V*_{Y}, *V*_{Z}) up to *P*^{′} and passing through *P*. Point *V* is referred to as the *point of projection*. Vectors *P* and *P*^{′} correspond to the vectors that go from the origin with coordinates (0, 0, 0) to (*x*, *y*, *z*) and to (*x*^{′}, *y*^{′}, *z*^{′}), respectively.

*i*,

*j*, and

*k*, as depicted in Figure 4-1. For simplicity, the screen is placed parallel to the

*x*−

*y*plane and the normal distance between planes is

*D*.

*A*denote the vector from point

*V*to

*P*and let

*B*denote the vector from point

*V*to

*P*

^{′}. As both vectors are parallel to each other, we can write:

In Equation (4.1), *t* is a scalar.

*X*

_{C},

*Y*

_{C}). Vector

*Q*corresponds to the vector that goes from (0, 0) to (

*X*

_{C},

*Y*

_{C}). Vector

*T*goes from (

*X*

_{C},

*Y*

_{C}) to

*P*

^{′}, while vector

*R*goes from (0, 0) to

*P*

^{′}. As these three vectors are on the screen, each one of them is normal to

*k*.

*Dk*goes from (0 ,0, 0) to the center of the screen, we can write:

*T*is normal to

*k*, the dot product vanishes. Therefore, the dot product of Equation (4.7) with

*k*gives the following:

To obtain Equation (4.9), we used *P* = *Dk*.

Note from Figure 4-1 that *z* in Equation (4.9) is the distance from the origin (0, 0, 0) to point *P*, along the unitary *k* vector. For programming purposes, it is more convenient to measure this distance starting from the screen. This distance is denoted as *Z*_{P}. Therefore, *z* = *D* − *Z*_{P}. This value will be substituted in Equation (4.9).

*t*given by Equation (4.9) and the value of

*T*obtained from Equation (4.5) to rewrite Equation (4.7) as follows:

In Equation (4.10), we substituted *z* with *D* − *Z*_{P}.

Equation (4.10) allows us to calculate the coordinates of point *P*^{′} on the screen. For this, according to Figure 4-2, we will express vectors *R* and *Q* on the screen as *R* = *X*_{P}*i* + *Y*_{P}*j* and *Q* = *X*_{C}*i* + *Y*_{C}*j*. Therefore, Equation (4.10) gives the position of point *P*^{′} in terms of the vector pointing to the center of the screen (*Q*), the normal distance to the screen (D), the vector of projection (*V*), and the position of the three-dimensional point (*P*).

*R*=

*X*

_{P}

*i*+

*Y*

_{P}

*j*and

*Q*=

*X*

_{C}

*i*+

*Y*

_{C}

*j*in Equation (4.10), the vector components give the following three equations:

Equations (4.11) and (4.12) represent the main tool for determining the projection of the three-dimensional point on the screen. Equation (4.13), although algebraically correct, will not be used, as it does not provide further information.

In addition to Equations (4.11) and (4.12), we will also need equations to rotate the polygons. In the following section, we obtain these equations.

## 4.2 Rotating a Point on a Plane

Rotation equations for a three-dimensional point projected on a screen can be calculated by successive rotations performed in two-dimensional planes. Therefore, our description here is presented in a two-dimensional space.

*x*

^{′},

*y*

^{′}), is given by the position vector

*C*on a coordinate plane (

*x*,

*y*).

*x*,

*y*) space. As depicted,

*P*and

*C*represent vectors going from the origin of the (

*x*,

*y*) system to the point and to the center of the screen, respectively. Vector

*R*

^{′}goes from the center of the screen to the point. It can be observed that:

It will also be noticed that:

*i* = *i*^{′} and *j* = *j*^{′} (4.18)

*θ*, as illustrated in Figure 4-4, the coordinates of the rotated point remain fixed on the screen.

In Equations (4.20) and (4.21), we substituted *i*^{′} and *j*^{′} with their corresponding values given in Equation (4.18).

*x*

^{′}and

*y*

^{′}can be calculated using the component vectors of Equation (4.14) as:

*R*

^{′′}in Equation (4.23) and using Equations (4.24) and (4.25), we obtain the following:

Equations (4.26) and (4.27) give the coordinates of the rotated point. These equations are used in Chapter 5 to program the rotation of the polygons.

## 4.3 Summary

In this chapter, we derived analytical equations for projecting three-dimensional points onto a two-dimensional screen. Additionally, we obtained equations to calculate the rotation of points in a three-dimensional space. These equations are used in Chapter 5 to position and rotate polygons on the screen.