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 (VX, VY, VZ) 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.

Projection on a screen of a point P with coordinates (x, y, z) to a point P′with coordinates (x′, y′, z′). The point of projection has coordinates (VX, VY, VZ). Their corresponding vectors are P, P′, and V, respectively

In Equation (4.1), t is a scalar.



Vectors Q, T, and R on the screen




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 ZP. Therefore, z = D − ZP. This value will be substituted in Equation (4.9).

In Equation (4.10), we substituted z with D − ZP.
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 = XPi + YPj and Q = XCi + YCj. 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).



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.

Screen with coordinates (x′, y′) on a coordinate plane (x, y)




It will also be noticed that:
i = i′ and j = j′ (4.18)

Rotated screen with coordinates (x′′, y′′). The coordinate system (x, y) remains static. The point on the screen represented by the black dot rotates with the screen, remaining fixed on it
In Equations (4.20) and (4.21), we substituted i′ and j′ with their corresponding values given in Equation (4.18).



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.