In this chapter, we cover basic equations for rotating two-dimensional points and mapping them on the computer’s screen.

## 2.1 Rotation Equations

*x*,

*y*) has two-unit direction vectors,

*i*and

*j*. Analogously, in the rotated system with coordinates (

*x*

^{′},

*y*

^{′}) the direction vectors are

*i*

^{′}and

*j*

^{′}. The angle of rotation between both coordinate systems is

*θ*, as depicted in Figure 2-1.

*P*in both systems as:

*x*,

*y*) corresponds to the screen and the coordinate system (

*x*

^{′},

*y*

^{′}) corresponds to a reference system that rotates around the origin. Thus, from Equations (2.5) and (2.6), we express the (

*x*

^{′},

*y*

^{′}) coordinates as:

Equations (2.7) and (2.8) are used in our programs to rotate the polygons.

## 2.2 Mapping Spatial Two-Dimensional Points to the Screen

To correctly map points from a two-dimensional Cartesian coordinate plane to the computer’s screen, it is necessary to consider inherent differences between them. On the Cartesian, two-dimensional plane, a pair of real numbers *(x, y)* determines the position of a determined point. In contrast, in a computer display, pixels are arranged in a two-dimensional grid in which a pair of integer numbers, which we will denote as *(n, m),* determines the position of a pixel. The integer *n* corresponds to the column index of the pixel and *m* to its row index. Thus, mapping points from a two-dimensional coordinate system to the computer’s screen requires mapping pairs of floating numbers *(x, y)* to pairs of integer numbers *(n, m)*. Strictly speaking, the function in charge of this task is not bijective.

To obtain analytical relations between the Cartesian coordinate plane and the screen, we first assume that the coordinates of the points on the screen are real numbers rather than integers. This assumption will not alter the results because, in the end, we will take the integer part of the calculated values.

For our calculations, let’s draw two coordinate planes, one below the other, as depicted in Figure 2-2. The upper drawing is a region of a Cartesian coordinate plane around the origin. The lower one consists of a rectangle region on the Cartesian plane resembling the computer’s screen with its center shifted from (0, 0). We want to obtain analytical expressions to map points, from the upper coordinate plane to the ones on the screen on the lower Cartesian plane. The procedure is as follows.

Let’s consider a point on the upper Cartesian (x, y) plane, pointed by vector *P* and a point with coordinates (*x*_{p}, *y*_{p}) pointed by vector *Q* on the screen, on the lower plane, as shown in Figure 2-2.

*Q*on the computer’s screen to be a scaled version of

*P*. We have to fulfill this requirement with each vertex of the polygons, built in the Cartesian plane, to display a scaled version of them on the screen.

Based on this description, we will write *Q* = *ScaleP*. Here, the scale factor is represented by the parameter *Scale*.

*R*=

*C*+

*Q*;

*R*=

*X*

_{p}

*i*+

*Y*

_{p}

*j*, and

*C*=

*X*

_{C}

*i*+

*Y*

_{C}

*j*. The coordinates (

*X*

_{c},

*Y*

_{C}) represent the center of the screen. It then results that:

In Equations (2.10) and (2.11), we have increased the scaling options by introducing two independent scaling terms in the x and y directions, *Scale* _ *X* and *Scale* _ *Y*. Since we need to shift the points to other regions of the screen, we have introduced additional shifting parameters, (*X*_{0}, *Y*_{0}).

Equations (2.7)-(2.8) and (2.10)-(2.11) can be used for constructing and rotating polygons in a two-dimensional space and displaying them on the computer’s screen. In the following chapter, we illustrate the use of these equations.

## 2.3 Summary

In this chapter, we obtained analytical equations for rotating points in a two-dimensional Cartesian plane. Additionally, we derived analytical equations for mapping them on the computer’s screen. These equations are used in the following chapter to construct two-dimensional polygons in a two-dimensional coordinate system to be displayed and rotated on the computer’s screen.